1

I Just wanted to get

#include<bits/stdc++.h>
using namespace std;

int main()
{
system("cls");

int t; cin>>t;
while(t--)
{
     
}
     exit(0);
}

auto-complete snippet when i type #include in VS code

so inside cpp.json file of vs code added this

    {
    
            "Print to console": {
                "prefix": "#include"
                "body": [
        "#include<bits/stdc++.h>"
        "using namespace std;\n"
        "int main()"
        "{"
        "system("cls");\n"
        "int t; cin>>t;"
        "while(t--)"
        "{"
        "\t $1"
        "}"
        "\t exit(0);"
        "}"
            ],
                "description": "basic structure for CP"
            }
  }

But when i get the snippet the "cls" word is not getting printed instead iam getting the output as

#include<bits/stdc++.h>
using namespace std;

int main()
{
system(
);

int t; cin>>t;
while(t--)
{
     
}
     exit(0);
}

"cls" is missing.

can anyone help me sorting out the issue

you can even suggest me any other command or way to clear screen automatically before output using code itself if any alternative for system("cls") in VS code which doesn't give me this problem when set in user snippet.

  • 2
    You need to escape the `"` characrer such that `\"`. Also don't use `using namespace std;` or `#include ` – Lala5th Jul 12 '21 at 07:26
  • @Lala5th why do you suggest not to use `using namespace std` or `#include` what is the problem in using this ? – S Mahesh Kumar Jul 12 '21 at 07:28
  • @HemanthKollipara tried that !!...it will give me `cls` in snippet but it dont clear the screen as `system('cls');` isnt a valid command ! – S Mahesh Kumar Jul 12 '21 at 07:29
  • @MOHAN `using namespace std;` creates namespace pollution: https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice. `#include ` increases compile time and file size not to mention that it is not standard `c++`. For quick programs where time is an issue (i.e. competitions) it's fine but it is generally very bad practice. – Lala5th Jul 12 '21 at 07:30
  • Lala5th THANKS FOR YOUR REPLY !!....IT WORKED !!!...By USING CONCEPT OF ESCAPE SEQUENCE – S Mahesh Kumar Jul 12 '21 at 07:31
  • @Lala5th yeah now i get it ...thanks ! – S Mahesh Kumar Jul 12 '21 at 07:32

1 Answers1

1

Your problem is that you must escape the double quotes for your string in order to be a valid JSON. So just use the \ character in front like this:

"system(\"cls\");\n"
Costa
  • 1,794
  • 1
  • 12
  • 21