VS代码中的用户代码段问题



我只是想得到

#include<bits/stdc++.h>
using namespace std;
int main()
{
system("cls");
int t; cin>>t;
while(t--)
{

}
exit(0);
}

在VS代码中键入#include时自动完成代码段

所以在vs代码的cpp.json文件中添加了这个

{

"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"
}
}

但当我得到这个片段时;cls";单词没有打印出来,而是作为输出

#include<bits/stdc++.h>
using namespace std;
int main()
{
system(
);
int t; cin>>t;
while(t--)
{

}
exit(0);
}

"cls";缺少。

有人能帮我解决问题吗

您甚至可以建议我使用代码本身在输出之前自动清除屏幕的任何其他命令或方法如果VS代码中system("cls")的任何替代方案在用户代码段中设置时不会给我带来这个问题。

您的问题是必须转义字符串的双引号才能成为有效的JSON。所以只需在前面使用字符,如下所示:

"system("cls");n"

最新更新