Ubuntu VSCode 配置C++环境

首先确保自己有g++

在命令行输入 g++ --version

 如果没有就下在一下:

sudo apt install g++

然后,建立一个C++ 工作环境,其实就是一个文件夹,我把这个文件夹命名为“C++环境”

以后,我们想要使用C++工作环境,就在这个文件里面放置对应的代码就好了

打开“C++环境” 文件夹,在里面新建一个test.cpp 用作尝试代码:

#include<iostream>
using namespace std;
 
int main()
{
    cout << "hello world!" <<endl;
    return 0;
}

然后,在C++环境文件夹下面建立一个名为 .vscode   的文件夹

在这个文件夹里面添加两个文件 : launch.json tasks.json 文件


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": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,	//如果不要窗口弹出,在ide中显示,就设置成 false
            "MIMode": "gdb",
            "preLaunchTask": "build",   //表示预先生成一个中间文件,用于g++运行
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

tasks.json 文件内容如下:

{
    // 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": ["-g", "${file}", "-std=c++11", "-o", "${fileBasenameNoExtension}.out"]	//相当于 g++ -g main.cpp -std=c++11 -o main.out
        }
    ]
}

然后再次运行test.cpp ,输出正确就说明没啥问题啦

ref :

记录一次ubuntu18.04安装 vscode并且配置C++调试环境_lx127372的博客-CSDN博客_ubuntu18.04安装vscode

Ubuntu18.04下配置VScode的C/C++开发环境_Zero_to_zero1234的博客-CSDN博客_ubuntu安装配置vscode Ubuntu20.04下安装VSCode(配置C/C++开发环境)_fangshuo_light的博客-CSDN博客_ubuntu安装vscode

  • 10
    点赞
  • 62
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值