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.

6
  • 2
    You need to escape the " characrer such that \". Also don't use using namespace std; or #include <bits/stdc++.h> Commented Jul 12, 2021 at 7:26
  • @Lala5th why do you suggest not to use using namespace std or #include<bits/stdc++.h> what is the problem in using this ? Commented Jul 12, 2021 at 7:28
  • @HemanthKollipara tried that !!...it will give me cls in snippet but it dont clear the screen as system('cls'); isnt a valid command ! Commented Jul 12, 2021 at 7:29
  • @MOHAN using namespace std; creates namespace pollution: stackoverflow.com/questions/1452721/…. #include <bits/stdc++.h> 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. Commented Jul 12, 2021 at 7:30
  • Lala5th THANKS FOR YOUR REPLY !!....IT WORKED !!!...By USING CONCEPT OF ESCAPE SEQUENCE Commented Jul 12, 2021 at 7:31

1 Answer 1

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"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.