在VS代码中添加字符串

发布于 2025-02-14 01:51:06 字数 439 浏览 3 评论 0原文

我试图添加一个自定义片段,但是在片段中添加字符串的问题是代码:

"Default cpp formate": {
    "prefix": [
        "include",
        "default"
    ],
    "body": [
        "#ifndef ONLINE_JUDGE"
            "   freopen("input.txt", "r", stdin);"
            "   freopen("output.txt", "w", stdout);"
        "#endif"
            
        "$0",
        ""
    ],
    "description": "This is a c++ snippet",
}

在代码中,“ input.txt”运行摘要时不会出现

I was trying to add a custom snippet but having a problem adding string to the snippet here is the code:

"Default cpp formate": {
    "prefix": [
        "include",
        "default"
    ],
    "body": [
        "#ifndef ONLINE_JUDGE"
            "   freopen("input.txt", "r", stdin);"
            "   freopen("output.txt", "w", stdout);"
        "#endif"
            
        "$0",
        ""
    ],
    "description": "This is a c++ snippet",
}

In the code the "input.txt" does not come when run the snippet

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隔纱相望 2025-02-21 01:51:06

因此,最终,此代码在每个引号之前都使用逃生序列“/”来工作

"Default cpp formate": {
    "prefix": [
        "include",
        "default"
    ],
    "body": [
        "#ifndef ONLINE_JUDGE",
            "   freopen(\"input.txt\", \"r\", stdin);",
            "   freopen(\"output.txt\", \"w\", stdout);",
        "#endif",
        "$0",
        ""
    ],
    "description": "This is a c++ sniffpet",
},
"for loop": {
    "prefix": "forl",
    "body": [
        "for($1 $2 = $3 ; $2 < $4 ; $2++)",
        "{","   ${0:/* code */}",
        "}"
    ],
    "description": "For Loop"
}

}

So finally this code worked using escape sequences "/" before every quotes

"Default cpp formate": {
    "prefix": [
        "include",
        "default"
    ],
    "body": [
        "#ifndef ONLINE_JUDGE",
            "   freopen(\"input.txt\", \"r\", stdin);",
            "   freopen(\"output.txt\", \"w\", stdout);",
        "#endif",
        "$0",
        ""
    ],
    "description": "This is a c++ sniffpet",
},
"for loop": {
    "prefix": "forl",
    "body": [
        "for($1 $2 = $3 ; $2 < $4 ; $2++)",
        "{","   ${0:/* code */}",
        "}"
    ],
    "description": "For Loop"
}

}

喜爱纠缠 2025-02-21 01:51:06

摘要是在执行CP时节省时间的好方法。要回答您的问题,您可以使用下面的片段,也无需包含自定义标签空间。 \ t将为您添加选项卡空间。

{
    "cp-extension": {
      "prefix": ["cpp-cp"],
      "body": ["#include <bits/stdc++.h>",
"using namespace std;",
"#define ll long long",
"#define ll long long int",
"#define sz(A) (int)(A).size()",
"#define mp make_pair",
"#define pb push_back",
"#define fr(i,A) for(int i=0;i<A.size();i++)",
"#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"
    }
,

Snippets are a good way to save time while doing cp. To answer your question you can use the snippet below and also there is no need to include custom tab spaces. \t will add tab spaces for you.

{
    "cp-extension": {
      "prefix": ["cpp-cp"],
      "body": ["#include <bits/stdc++.h>",
"using namespace std;",
"#define ll long long",
"#define ll long long int",
"#define sz(A) (int)(A).size()",
"#define mp make_pair",
"#define pb push_back",
"#define fr(i,A) for(int i=0;i<A.size();i++)",
"#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"
    }
,
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文