zoukankan      html  css  js  c++  java
  • VS Code编译C/C++

    如何让VSCode做C++开发的IDE?

    1.安装MINGW, 配置PATH

    编译器安装成功

    2.安装VS 插件

    在terminal调试下

    3.配置 launch.json, 项目根目录.vscode下。复制进去之后要修改miDebuggerPath参数,这里面填写自己的gdb.exe路径,编译配置已完成。

    {
        // 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": "(gdb) Launch",
                "type": "cppdbg",
                "request": "launch",
                "program": "${file}.exe",
                "args": [],
                "stopAtEntry": false,
                "cwd": "${workspaceRoot}",
                "environment": [],
                "externalConsole": true,
                "MIMode": "gdb",
                "miDebuggerPath": "C:\MinGW\bin\gdb.exe",
                "preLaunchTask": "g++",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            }
        ]
    }
    

    4.Ctrl+Shift+P,输入Tasks:Configure Task,之后选择使用模板创建tasks.json文件, 同样保存在根目录.vscode下  

    {
        // See https://go.microsoft.com/fwlink/?LinkId=733558
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "command": "g++",
        "args": ["-g","${file}","-o","${file}.exe"],    // 编译命令
        "problemMatcher": {
            "owner": "cpp",
            "fileLocation": ["relative", "${workspaceRoot}"],
            "pattern": {
                "regexp": "^(.*):(\d+):(\d+):\s+(warning|error):\s+(.*)$",
                "file": 1,
                "line": 2,
                "column": 3,
                "severity": 4,
                "message": 5
            }
        }
    }
    

      

    5. 按F5即可执行,如果console控制台只闪出来一下,不能观察到结果,解决办法是在return 0之前增加一句system("pause"),缺点在于每个文件都要写,不知道有没有更好的办法。

    参考: https://blog.csdn.net/qq_39630587/article/details/79826652

       https://www.zhihu.com/question/30315894 

  • 相关阅读:
    【Rollo的Python之路】Python 编码与解码
    【Rollo的Python之路】Python 队列 学习笔记 queue
    【Rollo的Python之路】Python 同步条件 学习笔记 Event
    【Rollo的Python之路】Python 条件变量同步 学习笔记 Condition
    【Rollo的Python之路】Python 信号量 学习笔记 Semaphore
    十天冲刺-09
    十天冲刺-08
    十天冲刺-07
    十天冲刺-06
    十天冲刺-05
  • 原文地址:https://www.cnblogs.com/7star/p/12566246.html
Copyright © 2011-2022 走看看