{"id":294,"date":"2023-10-08T14:55:48","date_gmt":"2023-10-08T06:55:48","guid":{"rendered":"http:\/\/www.forillusion.com\/?p=294"},"modified":"2025-02-14T11:39:27","modified_gmt":"2025-02-14T03:39:27","slug":"vscode-environment","status":"publish","type":"post","link":"https:\/\/www.forillusion.com\/index.php\/vscode-environment\/","title":{"rendered":"\u5229\u7528Dev-C++\u914d\u7f6eVS Code\u7684C++\u73af\u5883"},"content":{"rendered":"\n<p><div class=\"has-toc have-toc\"><\/div><\/p>\n\n\n\n<p>\u672c\u6587\u5229\u7528Dev-C++\u4e2d\u73b0\u6709\u7684\u7f16\u8bd1\u5668\uff0c\u6765\u914d\u7f6eVS Code\u7684C++\u8fd0\u884c\u73af\u5883\uff0c\u5e76\u652f\u6301C++11\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5c06\u7f16\u8bd1\u5668\u6dfb\u52a0\u5230\u73af\u5883\u4e2d<\/h2>\n\n\n\n<p>\u627e\u5230Dev-C++\u4e2d\u7684MinGW64\u7f16\u8bd1\u5668\u7684\u4f4d\u7f6e\uff0c\u901a\u5e38\u4f4d\u7f6e\u4e3a<\/p>\n\n\n\n<p><code>D:\\Program Files (x86)\\Dev-Cpp\\MinGW64<\/code><\/p>\n\n\n\n<p>\u6253\u5f00\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\uff0c\u6253\u5f00\u7528\u6237\u53d8\u91cf\u7684Path\uff0c\u6dfb\u52a0 <code>D:\\Program Files (x86)\\Dev-Cpp\\MinGW64\\bin<\/code><\/p>\n\n\n\n<p>\u6253\u5f00cmd\uff0c\u8f93\u5165 <code>gcc -v<\/code> \u6765\u68c0\u6d4b\u662f\u5426\u52a0\u5165\u6210\u529f\uff0c\u5982\u679c\u6dfb\u52a0\u5931\u8d25\uff0c\u4f1a\u8f93\u51fa<\/p>\n\n\n\n<p><code>'gcc' \u4e0d\u662f\u5185\u90e8\u6216\u5916\u90e8\u547d\u4ee4\uff0c\u4e5f\u4e0d\u662f\u53ef\u8fd0\u884c\u7684\u7a0b\u5e8f\u6216\u6279\u5904\u7406\u6587\u4ef6\u3002<\/code><\/p>\n\n\n\n<p>\u6dfb\u52a0\u6210\u529f\u540e\uff0c\u5728cmd\u4e2d\u8f93\u5165 <code>gcc -v -E -x c++ -<\/code> \u6765\u83b7\u53d6\u94fe\u63a5\u6587\u4ef6\u7684\u5730\u5740\uff0c\u5728cmd\u8f93\u51fa\u7684\u7ed3\u5c3e\uff0c\u80fd\u770b\u52307\u884c\u8def\u5f84\uff0c\u4fdd\u5b58\u4e0b\u6765\u8fd97\u884c\u8def\u5f84\u5f85\u4f1a\u9700\u8981\u7528\u5230\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u914d\u7f6eVS Code<\/h2>\n\n\n\n<p>VS Code \u5b89\u88c5<code>C\/C++<\/code> \uff0c <code>code runner<\/code> \u62d3\u5c55<\/p>\n\n\n\n<p>\u5728VScode\u4e2d\u6253\u5f00\u4e00\u4e2a\u5de5\u4f5c\u6587\u4ef6\u5939\uff0c\u6587\u4ef6\u5939\u76ee\u5f55\u9700\u8981\u5168\u82f1\u6587\u4e14\u65e0\u7279\u6b8a\u7b26\u53f7<\/p>\n\n\n\n<p>\u6253\u5f00\u540e\u4f1a\u5728\u5de6\u4fa7\u6587\u4ef6\u5939\u4e2d\u627e\u5230\u4e00\u4e2a\u540d\u53eb <code>.vscode<\/code> \u7684\u6587\u4ef6\u5939\uff0c\u6253\u5f00\u91cc\u9762\u7684\u4e09\u4e2a\u6587\u4ef6\uff1a<code>launch.json<\/code>\u3001<code>tasks.json<\/code>\u3001<code>c_cpp_properties.json<\/code>\u3002<strong>\u6ce8\u610f\u8981\u4fee\u6539\u8def\u5f84<\/strong><\/p>\n\n\n\n<p><code> launch.json <\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"version\": \"0.2.0\",\n    \"configurations\": &#91;\n        {\n            \"name\": \"(gdb) \u542f\u52a8\",\n            \"type\": \"cppdbg\",\n            \"request\": \"launch\",\n            \"program\": \"${fileDirname}\\\\${fileBasenameNoExtension}.exe\",\n            \"args\": &#91;],\n            \"stopAtEntry\": false,\n            \"cwd\": \"${fileDirname}\",\/\/\u6307\u9ed8\u8ba4\u6587\u4ef6\u64cd\u4f5c\u7684\u76ee\u5f55\uff08\u5982fopen\u7684\u9ed8\u8ba4\u5bfb\u627e\u4f4d\u7f6e\uff09\uff0c${fileDirname}\u662fC\/C++\u6587\u4ef6\u7684\u76ee\u5f55\uff0c\u4fee\u6539\u4e3a${workspaceFolder}\u5c31\u662f\u5de5\u4f5c\u6587\u4ef6\u5939\u76ee\u5f55\n            \"environment\": &#91;],\n            \"externalConsole\": true,\n            \"MIMode\": \"gdb\",\n            \"miDebuggerPath\": \"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\/gdb.exe\",\/\/\u8def\u5f84\u8981\u4fee\u6539\n            \"setupCommands\": &#91;\n                {\n                    \"description\": \"\u4e3a gdb \u542f\u7528\u6574\u9f50\u6253\u5370\",\n                    \"text\": \"-enable-pretty-printing\",\n                    \"ignoreFailures\": true\n                }\n            ],\n            \"preLaunchTask\": \"C\/C++: gcc.exe \u751f\u6210\u6d3b\u52a8\u6587\u4ef6\"\n        }\n    ]\n}\n<\/code><\/pre>\n\n\n\n<p><code>tasks.json<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"version\": \"2.0.0\",\n    \"command\": \"gcc\",\n    \"args\": &#91;\n        \"-std=c++11\",\/\/C++11\n        \"-static-libgcc\",\n        \"-g\",\n        \"${file}\",\n        \"-o\",\n        \"${file}.exe\"\n    ],\n    \"problemMatcher\": {\n        \"owner\": \"cpp\",\n        \"fileLocation\": &#91;\n            \"relative\",\n            \"${workspaceRoot}\"\n        ],\n        \"pattern\": {\n            \"regexp\": \"^(.*):(\\\\d+):(\\\\d+):\\\\s+(warning|error):\\\\s+(.*)$\",\n            \"file\": 1,\n            \"line\": 2,\n            \"column\": 3,\n            \"severity\": 4,\n            \"message\": 5\n        }\n    },\n    \"presentation\": {\n        \"echo\": true,\n        \"reveal\": \"always\",\n        \"focus\": false,\n        \"panel\": \"new\",\n        \"showReuseMessage\": true,\n        \"clear\": false\n    },\n    \"tasks\": &#91;\n        {\n            \"type\": \"cppbuild\",\n            \"label\": \"C\/C++: gcc.exe \u751f\u6210\u6d3b\u52a8\u6587\u4ef6\",\n            \"command\": \"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\/g++.exe\",\/\/\u8def\u5f84\u8981\u4fee\u6539\n            \"args\": &#91;\n                \"-std=c++11\",\/\/C++11\n                \"-static-libgcc\",\n                \"-g\",\n                \"${file}\",\n                \"-o\",\n                \"${fileDirname}\\\\${fileBasenameNoExtension}.exe\"\n            ],\n            \"options\": {\n                \"cwd\": \"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\"\/\/\u8def\u5f84\u8981\u4fee\u6539\n            },\n            \"problemMatcher\": &#91;\n                \"$gcc\"\n            ],\n            \"group\": \"build\",\n            \"detail\": \"\u7f16\u8bd1\u5668: \\\"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\/g++.exe\\\"\"\/\/\u8def\u5f84\u8981\u4fee\u6539\n        },\n        {\n            \"type\": \"cppbuild\",\n            \"label\": \"C\/C++: g++.exe \u751f\u6210\u6d3b\u52a8\u6587\u4ef6\",\n            \"command\": \"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\/g++.exe\",\/\/\u8def\u5f84\u8981\u4fee\u6539\n            \"args\": &#91;\n                \"-std=c++11\",\/\/C++11\n                \"-static-libgcc\",\n                \"-fdiagnostics-color=always\",\n                \"-g\",\n                \"${file}\",\n                \"-o\",\n                \"${fileDirname}\\\\${fileBasenameNoExtension}.exe\"\n            ],\n            \"options\": {\n                \"cwd\": \"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\"\/\/\u8def\u5f84\u8981\u4fee\u6539\n            },\n            \"problemMatcher\": &#91;\n                \"$gcc\"\n            ],\n            \"group\": {\n                \"kind\": \"build\",\n                \"isDefault\": true\n            },\n            \"detail\": \"\u8c03\u8bd5\u5668\u751f\u6210\u7684\u4efb\u52a1\u3002\"\n        }\n    ]\n}\n\n<\/code><\/pre>\n\n\n\n<p><code>c_cpp_properties.json<\/code><\/p>\n\n\n\n<p>\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\uff0c\u9700\u8981\u586b\u5199\u4e4b\u524d\u4ececmd\u4e2d\u5f97\u5230\u76847\u884c\u8def\u5f84\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"configurations\": &#91;\n        {\n            \"name\": \"Win32\",\n            \"includePath\": &#91;\n                \"${workspaceFolder}\/**\",\n                \"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\/..\/lib\/gcc\/x86_64-w64-mingw32\/4.9.2\/include\/c++\",\/\/\u8def\u5f84\u8981\u4fee\u6539\n                \"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\/..\/lib\/gcc\/x86_64-w64-mingw32\/4.9.2\/include\/c++\/x86_64-w64-mingw32\",\/\/\u8def\u5f84\u8981\u4fee\u6539\n                \"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\/..\/lib\/gcc\/x86_64-w64-mingw32\/4.9.2\/include\/c++\/backward\",\/\/\u8def\u5f84\u8981\u4fee\u6539\n                \"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\/..\/lib\/gcc\/x86_64-w64-mingw32\/4.9.2\/include\",\/\/\u8def\u5f84\u8981\u4fee\u6539\n                \"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\/..\/lib\/gcc\/x86_64-w64-mingw32\/4.9.2\/..\/..\/..\/..\/include\",\/\/\u8def\u5f84\u8981\u4fee\u6539\n                \"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\/..\/lib\/gcc\/x86_64-w64-mingw32\/4.9.2\/include-fixed\",\/\/\u8def\u5f84\u8981\u4fee\u6539\n                \"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\/..\/lib\/gcc\/x86_64-w64-mingw32\/4.9.2\/..\/..\/..\/..\/x86_64-w64-mingw32\/include\"\/\/\u8def\u5f84\u8981\u4fee\u6539\n            ],\n            \"defines\": &#91;\n                \"_DEBUG\",\n                \"UNICODE\",\n                \"_UNICODE\"\n            ],\n            \"compilerPath\": \"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\/g++.exe\",\n            \"cStandard\": \"c99\",\n            \"cppStandard\": \"c++11\",\n            \"intelliSenseMode\": \"gcc-x64\"\n        }\n    ],\n    \"version\": 4\n}<\/code><\/pre>\n\n\n\n<p>\u4fdd\u5b58\u6210\u529f\u540e\uff0c\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\u5e76\u4fdd\u5b58\u5728\u5de5\u4f5c\u6587\u4ef6\u5939\u4e0b\uff0c\u6309\u4e0b <code>F5<\/code> \u7f16\u8bd1\u8fd0\u884c\uff0c<strong>\u6ce8\u610f\u6587\u4ef6\u540d\u4e0d\u80fd\u51fa\u73b0\u4e2d\u6587\uff01<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u8fd0\u884c\u540e\u95ea\u9000\u7684\u89e3\u51b3<\/h2>\n\n\n\n<p>\u4e0a\u9762\u7684 <code> launch.json <\/code> \u4e2d\u662f\u901a\u8fc7\u76f4\u63a5\u542f\u52a8\u7f16\u8bd1\u5668\u751f\u6210\u7684.exe\u6587\u4ef6\u6765\u8fd0\u884c\u7684\uff0c\u8fd0\u884c\u7ed3\u675f\u540e\u7a0b\u5e8f\u4f1a\u7acb\u523b\u9000\u51fa\u3002\u8fd9\u91cc\u53ef\u4ee5\u5229\u7528cmd\u6765\u8fd0\u884c\u751f\u6210\u7684.exe\u6587\u4ef6\u5e76\u6dfb\u52a0\u4e0a <code>pause<\/code> \uff0c\u4f7f\u5f97\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u675f\u540e\u4e0d\u4f1a\u7acb\u523b\u9000\u51fa\u3002<\/p>\n\n\n\n<p>\u5c06 <code> launch.json <\/code> \u4fee\u6539\u4e3a\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"version\": \"0.2.0\",\n    \"configurations\": &#91;\n        {\n            \"name\": \"(gdb) \u542f\u52a8\",\n            \"type\": \"cppdbg\",\n            \"request\": \"launch\",\n            \"program\": \"C:\\\\Windows\\\\system32\\\\cmd.exe\",\n            \"args\": &#91;\n                \"\/C\",\n                \"${fileDirname}\\\\${fileBasenameNoExtension}.exe\",\n                \"&amp;\",\n                \"pause\"\n            ],\n            \"stopAtEntry\": false,\n            \"cwd\": \"${fileDirname}\",\/\/\u6307\u9ed8\u8ba4\u6587\u4ef6\u64cd\u4f5c\u7684\u76ee\u5f55\uff08\u5982fopen\u7684\u9ed8\u8ba4\u5bfb\u627e\u4f4d\u7f6e\uff09\uff0c${fileDirname}\u662fC\/C++\u6587\u4ef6\u7684\u76ee\u5f55\uff0c\u4fee\u6539\u4e3a${workspaceFolder}\u5c31\u662f\u5de5\u4f5c\u6587\u4ef6\u5939\u76ee\u5f55\n            \"environment\": &#91;],\n            \"externalConsole\": true,\n            \"MIMode\": \"gdb\",\n            \"miDebuggerPath\": \"D:\/Program Files (x86)\/Dev-Cpp\/MinGW64\/bin\/gdb.exe\",\/\/\u628a\u8fd9\u4e2a\u8def\u5f84\u6539\u6210\u81ea\u5df1\u7535\u8111\u7684gdb.exe\u8def\u5f84\n            \"setupCommands\": &#91;\n                {\n                    \"description\": \"\u4e3a gdb \u542f\u7528\u6574\u9f50\u6253\u5370\",\n                    \"text\": \"-enable-pretty-printing\",\n                    \"ignoreFailures\": true\n                },\n                {\n                    \"description\": \"\u5c06\u53cd\u6c47\u7f16\u98ce\u683c\u8bbe\u7f6e\u4e3a Intel\",\n                    \"text\": \"-gdb-set disassembly-flavor intel\",\n                    \"ignoreFailures\": true\n                }\n            ],\n            \"preLaunchTask\": \"C\/C++: gcc.exe \u751f\u6210\u6d3b\u52a8\u6587\u4ef6\"\n        }\n    ]\n}<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u518d\u8fd0\u884c\u7a0b\u5e8f\uff0c\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u675f\u540e\u4f1a\u51fa\u73b0 <code>\u8bf7\u6309\u4efb\u610f\u952e\u7ee7\u7eed. . .<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7a0b\u5e8f\u8f93\u51fa\u4e2d\u6587\u65f6\u4e71\u7801\u7684\u89e3\u51b3<\/h2>\n\n\n\n<p>\u56e0\u4e3a\u63a7\u5236\u53f0\u6240\u7528\u7684\u7f16\u7801\u4e3aGBK\uff0c\u800cVS Code\u6240\u4f7f\u7528\u7684\u7f16\u7801\u4e3aUTF-8\uff0c\u4e24\u8005\u7f16\u7801\u4e0d\u4e00\u81f4\u5bfc\u81f4\u7684\u4e2d\u6587\u8f93\u51fa\u4e71\u7801\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u5c06VS Code\u6240\u4f7f\u7528\u7684\u7f16\u7801\u6539\u4e3aGBK\uff0c\u4e0e\u63a7\u5236\u53f0\u4fdd\u6301\u4e00\u81f4\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u5728VS Code\u4e2d\u6309 <code>Ctrl+Shift+P<\/code> ,\u8f93\u5165 <code>user<\/code> ,\u70b9\u51fb <code>\u6253\u5f00\u7528\u6237\u8bbe\u7f6e<\/code> \uff0c\u5728\u6253\u5f00\u754c\u9762\u7684\u6700\u4e0a\u65b9\u7684\u641c\u7d22\u680f\u91cc\u8f93\u5165 <code>encoding<\/code> \uff0c\u5728\u754c\u9762\u91cc\u7684\u4e0b\u62c9\u6846\u4e2d\u9009\u62e9 <code>Simplified Chinese (GBK)<\/code> \u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u5df2\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u5728\u6587\u4ef6\u7684\u53f3\u4e0b\u89d2\u70b9\u51fb <code>UTF-8<\/code> \uff0c\u5728\u4e0a\u65b9\u7684\u5f39\u51fa\u6846\u4e2d\u9009\u62e9 <code>\u901a\u8fc7\u7f16\u7801\u91cd\u65b0\u6253\u5f00<\/code> \uff0c \u9009\u62e9 <code>Simplified Chinese (GBK)<\/code> \uff0c\u8fd9\u65f6\u6587\u4ef6\u91cc\u6240\u6709\u7684\u4e2d\u6587\u90fd\u4f1a\u53d8\u6210\u4e71\u7801\uff0c\u5220\u9664\u518d\u91cd\u65b0\u8f93\u5165\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u7136\u540e\u518d\u8fd0\u884c\u7a0b\u5e8f\uff0c\u7a0b\u5e8f\u5c06\u6b63\u5e38\u8f93\u51fa\u4e2d\u6587\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5229\u7528Dev-C++\u4e2d\u73b0\u6709\u7684\u7f16\u8bd1\u5668\uff0c\u6765\u914d\u7f6eVS Code\u7684C++\u8fd0\u884c\u73af\u5883\uff0c\u5e76\u652f\u6301C++11\u3002 \u5c06\u7f16\u8bd1\u5668\u6dfb\u52a0\u5230\u73af\u5883\u4e2d \u627e\u5230Dev- &#8230;<\/p>","protected":false},"author":1,"featured_media":375,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[23,24],"class_list":["post-294","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-3","tag-23","tag-24"],"_links":{"self":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/comments?post=294"}],"version-history":[{"count":1,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/294\/revisions"}],"predecessor-version":[{"id":1767,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/294\/revisions\/1767"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/media\/375"}],"wp:attachment":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/media?parent=294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/categories?post=294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/tags?post=294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}