强烈建议大家在 Linux 环境下学习 C++,window 的 gbk 实在是把我弄得焦头烂额。。。
安装 gcc g++ gdb
sudo apt-get gcc sudo apt-get g++ sudo apt-get ggb
配置 launch.json 这个文件在.vscode 里面
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", //配置名称,会在启动配置的下拉菜单中显示 "type": "cppdbg", //配置类型,只能为cppdbg "request": "launch", //请求类型,可以为launch或attach "program": "${workspaceFolder}/a.out", //将要调试的程序的路径 "args": [], //调试时传递给程序的命令行参数 "stopAtEntry": false, //设为true程序会暂停在入口处 "cwd": "${workspaceFolder}", //调试程序时的工作目录 "environment": [], //环境变量 "externalConsole": false, //调试时是否显示控制台窗口 "MIMode": "gdb", //指定连接的调试器,可以为gdb或lldb "miDebuggerPath": "/usr/bin/gdb", //gdb路径 "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "build" //调试开始前执行的任务,一般为编译程序 } ] }
配置 tasks.json 这个文件在.vscode 里面
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "g++", "args": [ "${file}", "-o", "${workspaceRoot}/a.out" ], "group": { "kind": "build", "isDefault": true } } ] }
配置完这两个文件就可以 F5 调试不报错了
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于