sar_warish's blog

By sar_warish, 3 years ago, In English

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.

The Code

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.

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it