【vscode配置】C/C++VScode配置文件

VScode配置C/C++

 

配置好后

写完代码按F5即可运行

program标签下的路径中 fileDirname为代码所在路径 workspaceFolder为工作区文件夹所在文件 

launch.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<code-pre class="code-pre" id="pre-FMTcsj"><code-line class="line-numbers-rows"></code-line>{ 
<code-line class="line-numbers-rows"></code-line>    <span class="hljs-attr">"version"</span>: <span class="hljs-string">"0.2.0"</span>, 
<code-line class="line-numbers-rows"></code-line>    <span class="hljs-attr">"configurations"</span>: [ 
<code-line class="line-numbers-rows"></code-line>        { 
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"name"</span>: <span class="hljs-string">"(gdb) Launch"</span>, <span class="hljs-comment">// 配置名称,将会在启动配置的下拉菜单中显示  </span>
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"type"</span>: <span class="hljs-string">"cppdbg"</span>,       <span class="hljs-comment">// 配置类型,这里只能为cppdbg  </span>
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"request"</span>: <span class="hljs-string">"launch"</span>,    <span class="hljs-comment">// 请求配置类型,可以为launch(启动)或attach(附加)  </span>
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"program"</span>: <span class="hljs-string">"${fileDirname}/${fileBasenameNoExtension}.exe"</span>,<span class="hljs-comment">// 将要进行调试的程序的路径  </span>
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"args"</span>: [],             <span class="hljs-comment">// 程序调试时传递给程序的命令行参数,一般设为空即可  </span>
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"stopAtEntry"</span>: <span class="hljs-literal">false</span>,   <span class="hljs-comment">// 设为true时程序将暂停在程序入口处,一般设置为false  </span>
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"cwd"</span>: <span class="hljs-string">"${workspaceFolder}"</span>, <span class="hljs-comment">// 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录  </span>
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"environment"</span>: [], 
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"externalConsole"</span>: <span class="hljs-literal">true</span>, <span class="hljs-comment">// 调试时是否显示控制台窗口,一般设置为true显示控制台  </span>
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"MIMode"</span>: <span class="hljs-string">"gdb"</span>, 
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"miDebuggerPath"</span>: <span class="hljs-string">"C:\\Program Files\\mingw64\\bin\\gdb.exe"</span>, <span class="hljs-comment">// miDebugger的路径,注意这里要与MinGw的路径对应  </span>
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"preLaunchTask"</span>: <span class="hljs-string">"g++"</span>, <span class="hljs-comment">// 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc  </span>
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"setupCommands"</span>: [ 
<code-line class="line-numbers-rows"></code-line>                {  
<code-line class="line-numbers-rows"></code-line>           <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Enable pretty-printing for gdb"</span>, 
<code-line class="line-numbers-rows"></code-line>                    <span class="hljs-attr">"text"</span>: <span class="hljs-string">"-enable-pretty-printing"</span>, 
<code-line class="line-numbers-rows"></code-line>                    <span class="hljs-attr">"ignoreFailures"</span>: <span class="hljs-literal">true</span> 
<code-line class="line-numbers-rows"></code-line>                } 
<code-line class="line-numbers-rows"></code-line>            ] 
<code-line class="line-numbers-rows"></code-line>        } 
<code-line class="line-numbers-rows"></code-line>    ] 
<code-line class="line-numbers-rows"></code-line>}
</code-pre>

tasks.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<code-pre class="code-pre" id="pre-KCYRNh"><code-line class="line-numbers-rows"></code-line>{
<code-line class="line-numbers-rows"></code-line>    <span class="hljs-comment">// See https://go.microsoft.com/fwlink/?LinkId=733558 </span>
<code-line class="line-numbers-rows"></code-line>    <span class="hljs-comment">// for the documentation about the tasks.json format</span>
<code-line class="line-numbers-rows"></code-line>    <span class="hljs-attr">"version"</span>: <span class="hljs-string">"2.0.0"</span>,
<code-line class="line-numbers-rows"></code-line>    <span class="hljs-attr">"tasks"</span>: [
<code-line class="line-numbers-rows"></code-line>        {
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"type"</span>: <span class="hljs-string">"shell"</span>,
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"label"</span>: <span class="hljs-string">"g++"</span>, <span class="hljs-comment">//这里注意一下,见下文</span>
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"command"</span>: <span class="hljs-string">"C:\\Program Files\\mingw64\\bin\\g++.exe"</span>,
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"args"</span>: [
<code-line class="line-numbers-rows"></code-line>                <span class="hljs-string">"-g"</span>,
<code-line class="line-numbers-rows"></code-line>                <span class="hljs-string">"${file}"</span>,
<code-line class="line-numbers-rows"></code-line>                <span class="hljs-string">"-o"</span>,
<code-line class="line-numbers-rows"></code-line>                <span class="hljs-string">"${fileDirname}\\${fileBasenameNoExtension}.exe"</span>
<code-line class="line-numbers-rows"></code-line>            ],
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"options"</span>: {
<code-line class="line-numbers-rows"></code-line>                <span class="hljs-attr">"cwd"</span>: <span class="hljs-string">"C:\\Program Files\\mingw64\\bin"</span>
<code-line class="line-numbers-rows"></code-line>            },
<code-line class="line-numbers-rows"></code-line>            <span class="hljs-attr">"problemMatcher"</span>: [
<code-line class="line-numbers-rows"></code-line>                <span class="hljs-string">"$gcc"</span>
<code-line class="line-numbers-rows"></code-line>            ]
<code-line class="line-numbers-rows"></code-line>        }
<code-line class="line-numbers-rows"></code-line>    ]
<code-line class="line-numbers-rows"></code-line>} </code-pre>

__EOF__

本文作者cheng_zhi
本文链接https://www.cnblogs.com/chengzhid/p/15206343.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   cheng_zhi  阅读(171)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示