折腾Vscode写C++
2024-10-21 03:34:55
一直以来都是用Sublime Text3写C/C++。因为ST配置简单,轻量。闲来没事才弄一弄。
1. 新建文件夹C++Code,并且再建立一个bulid文件夹来放要写的代码。
2. 在Vscode里新建.vscode文件夹,建立上图的3个文件(setting不需要)
2.1 Launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch (GDB)", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", // 配置类型,这里只能为cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"targetArchitecture": "x64", // 生成目标架构,一般为x86或x64
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe", // 重点!将要进行调试的程序的路径
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "${workspaceRoot}", // 调试程序时的工作目录,一般为${workspaceRoot}
"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
"internalConsoleOptions": "neverOpen", // 如果不设为neverOpen,调试时会跳到“调试控制台”选项卡",
"MIMode": "gdb", // 指定连接的调试器
"miDebuggerPath": "C:/Mingw64/bin/gdb.exe", //重点! 调试器路径
"setupCommands": [
{
"description": "Enable pretty-printing for GDB",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "Compile"
}
]
}主要改:"program", “miDebuggerPsth”.
2.2 tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile",
"command": "g++",
"args": [
"${file}", //指定编译源代码文件
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe", //重点! 指定输出文件名,不加该参数则默认输出a.exe
"-ggdb3", // 生成和调试有关的信息
"-Wall", // 开启额外警告
"-static-libgcc", // 静态链接
"-std=c++17", // 使用c++17标准
"-finput-charset=UTF-8", //输入编译器文本编码 默认为UTF-8
"-fexec-charset=GBK", //输出exe文件的编码
"-D _USE_MATH_DEFINES"
], "problemMatcher": {
"owner": "cpp",
"fileLocation": [
"absolute",
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": ,
"line": ,
"column": ,
"severity": ,
"message":
}
}, "type": "shell", "group": {
"kind": "build",
"isDefault": true
}, "presentation": {
"echo": true,
"reveal": "always", // 在“终端”中显示编译信息的策略,可以为always,silent,never
"focus": false,
"panel": "shared" // 不同的文件的编译信息共享一个终端面板
},
}
]
}
2.3 c_cpp_properties.json
{
"configurations": [
{
"name": "MinGW64",
"intelliSenseMode": "gcc-x64",
"compilerPath": "C:/Mingw64/bin/g++.exe", //重点! g++.exe所在路径
"includePath": [ //重点!
"${workspaceFolder}",
"C:/Mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/**",
"C:/Mingw64/x86_64-w64-mingw32/include/**"
], "browse": {
"path": [
"${workspaceFolder}",
"C:/Mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/**",
"C:/Mingw64/x86_64-w64-mingw32/include/**"
]
},
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version":
}
3. 在build里随便写个程序,按Ctrl+F5编译运行。
如果不想配置。在弄好MinGW环境变量的情况下,直接在Vscode里搜索 C/C++ Compile Run 插件,
写完代码后直接按F6编译运行。
最新文章
- Bootstrap之表单控件状态
- PHP基础 之 数组(一)
- Go 学习笔记(一)
- Drainage Ditches(Dinic最大流)
- iTunes 重新提交代码步骤
- app自动化的webView页面测试思路(appium工具)。
- Go语言Web框架gwk介绍2
- 10、桥接模式(Bridge)
- MongoDB--GridFS 文件存储系统
- jQery的链式操作和商城简易导航栏
- JAVA的helloworld
- thrift常见异常及原因分析(updating)
- 使用jQuery重置(reset)表单的方法
- 样本失衡会对SVM的影响
- HDU 1236 排名(Microsoft_zzt)
- 安装mysql时启动服务出错问题
- memcached缓存基本概念
- [转]:Android 5.0的调度作业JobScheduler
- 机器学习实战(一)k-近邻算法
- linux性能系列--块设备
热门文章
- (转)轻松应对IDC机房带宽突然暴涨问题
- escape、encodeURI以及encodeURIComponent
- 判断表单中是否含有disabled属性
- JQuery 技巧总结
- C语言答案解析
- [JAVA][Liferay] Duplicate key value violates unique constraint for resourcepermissionid in Liferay
- HTML标签_1
- 使用js来执行全屏
- (四)JavaScript之[break和continue]与[typeof、null、undefined]
- Android触摸事件MotionEvent详解