【实战】使用VSCode进行完整项目开发
士兵 类:
属性->姓名(许三多),枪
行为->开火、给枪装填子弹
枪 类:
属性->姓名(AK47),子弹数量
行为->发射子弹,装填子弹
先设计枪类
(1)合理设计项目目录
(2)编写项目源文件
修改main.cpp也只会将修改过的main.cpp重新编译
(3)编写CMakeLists.txt
cmake_minimum_required(VERSION 3.0) project(SOLIDERFIRE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") set(CMAKE_BUILD_TYPE Debug) include_directories(${CMAKE_SOURCE_DIR}/include) add_executable(my_cmake_exe main.cpp src/Gun.cpp src/Solider.cpp)
(4)编写CMake项目
(5)配置json文件并调试项目
create 啊 launch.json 选择 C++(GDB/LLDB)
修改launch.json文件和tasks.json文件
program:代表需要debug的可执行文件所在位置
prelauchTask:代表在debug之前需要进行的task,卸载右边的task.json中,在build文件夹下进行cmake.. 和 make操作
launch.json文件如下:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "g++ - Build and debug active file", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/build/my_cmake_exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "Set Disassembly Flavor to Intel", "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } ], "preLaunchTask": "Build", "miDebuggerPath": "/usr/bin/gdb" } ] }
tasks.json文件如下:
{ "version": "2.0.0", "options": { "cwd": "${workspaceFolder}/build" }, "tasks": [ { "type": "shell", "label": "cmake", "command": "cmake", "args": [ ".." ] }, { "label": "make", "group": { "kind": "build", "isDefault": true }, "command": "make", "args": [] }, { "label": "Build", "dependsOrder": "sequence", // 按列出的顺序执行任务依赖项 "dependsOn": [ "cmake", "make" ] } ] }
调试
fn+F10 单步越过
fn+F11 单步进入
如果进入库函数,想退出来 shift+fn+F11
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· [翻译] 为什么 Tracebit 用 C# 开发
· 腾讯ima接入deepseek-r1,借用别人脑子用用成真了~
· Deepseek官网太卡,教你白嫖阿里云的Deepseek-R1满血版
· DeepSeek崛起:程序员“饭碗”被抢,还是职业进化新起点?
· RFID实践——.NET IoT程序读取高频RFID卡/标签