(VSCode+Codeblocks)转自:https://blog.csdn.net/bat67/article/details/81268581
(吐槽一下:为什么现在不能带格式复制其他博客的内容了呢,好气哦;可能是版权的原因吧,感谢原作!!!)
针对该博客,主要修改以下几点:
1、实例C++文件(注意:test.cpp文件需要放在一个不含中文目录的文件夹下边,比如 C:\test\test.cpp)
#include<iostream>
#include<cstdlib>//system头文件
using namespace std;
int main(){
cout<<"Hello, world"<<endl;
system("pause");
return 0;
}
因为vscode不像IDE(比如codeblocks,VS等)在调试的时候黑框下面有点击任意键返回
,所以需要我们手动加一个断点,或者程序最后加一个getchar();
,或者加system("pause");
等
2、launch.json
的启动配置文件
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", // 配置类型,这里只能为cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录
"environment": [],
"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
"MIMode": "gdb",
//"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应
"miDebuggerPath": "C:\\Program Files (x86)\\CodeBlocks\\MinGW\\bin\\gdb32.exe",
"preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
3、tasks.json配置
文件
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++", //这里注意一下,见下文
//"command": "C:\\MinGW\\bin\\g++.exe",
"command": "C:\\Program Files (x86)\\CodeBlocks\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
//"cwd": "C:\\MinGW\\bin"
"cwd": "C:\\Program Files (x86)\\CodeBlocks\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
]
}
]
}
(VSCode+MinGW)友情链接参考:https://blog.csdn.net/bat67/article/details/76095813