VS code is one of the most widely used code editors by people around the world. In this post i will guide u to setup a small beginners default code sample for Cpp programmers and will provide u with a .json formatted text for use.
1 : Open VS code > File > Prefrences > User Snippets
2 : then select cpp from the drop down(or just type it in, if not available download a cpp code extension from the market : "C/C++ for Visual Studio Code")
3 : then paste below json code in the cpp.json file :
{
"cp-extension": {
"prefix": ["cpp-cp"],
"body": ["#include <bits/stdc++.h>",
"using namespace std;",
"#define ll long long",
"#define mod 1000000007\nvoid solve()",
"{",
"\t$2",
"}",
"int main() {\n\tios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);\n#ifndef ONLINE_JUDGE",
"\tfreopen(\"input.txt\", \"r\", stdin);",
"\tfreopen(\"output.txt\", \"w\", stdout);",
"#endif\n\n\tll test=1;\n//$1cin>>test;\n\twhile(test--)\n\t{\n\t\tsolve();\n\t}\n\treturn 0;\n}\n"
],
"description": "Default cpp code for CP"
}
}
4 : now save it
5 : open a new file with .cpp extension
6 : just type : cc and select cpp- cp from the dropdown..... That's it.
Snapshot of the code :/predownloaded/ca/5b/ca5b5b4ff27c2597a5f419ef1eac85fcbfb74da7.jpg
NB :
Initially test case is set to 1... uncomment cin>>test to take input
Make input.txt and output.txt in the same directory... Copy paste the Sample input in the input file , after code's execution the output will be displayed in the output.txt file. (if u still don't have a cpp compiler setup one, refer YOUTUBE and also set the path variable)
want to make some tweaks ? read : https://code.visualstudio.com/docs/editor/userdefinedsnippets
U may switch to GEANY when u become more comfortable with CP... Refer : Errichto 's video https://www.youtube.com/watch?v=ePZEkbbf3fc
Thank You.
Happy Coding.
what is for it?
define endl "\n"
Both endl and \n serve the same purpose in C++ – they insert a new line. However, the key difference between them is that endl causes a flushing of the output buffer every time it is called, whereas \n does not. hence reducing time of execution !! (saves a borderline TLE case )
BUT AVOID USING define endl "\n" in interactive problems !!!
Is it really that much harder to type
"\n"
compared toendl
? Don't add#define
s that you'll end up forgetting about and have to debug an interactive problem for three hours just to figure out you accidentally included#define endl "\n"
!#define nl "\n"
Yeah Goethermal does something similar, he does
const char nl = '\n';
.