ubuntu下载vscode并运行程序

如有帮助点赞收藏关注!
如需转载,请注明出处!

好久没有在linux下编译c++代码了,由于换了酷炫彩灯的电脑。又要重新安装一次喽。做个记录,可以帮助到有需要的人,接下来不要错过每一个步骤。
我们一起手把手运行vscode 的测试代码

VScode 下载与配置安装使用

  • ubuntu vscode下载
  • vscode配置
    • 安装g++
    • 安装中文版
    • 安装c++
  • 运行测试代码
    • 创建main.cpp
    • 修改launch和task文件

ubuntu vscode下载

下载链接
https://code.visualstudio.com/Download

windows下载到桌面上
ubuntu下载vscode并运行程序_第1张图片
然后拖拽到ubuntu系统的下载文件夹中
ubuntu下载vscode并运行程序_第2张图片
双击这个code App点击安装
ubuntu下载vscode并运行程序_第3张图片
安装好后就这样
ubuntu下载vscode并运行程序_第4张图片
打开终端:crtl+alt+T,输入code 回车。打开vscode
ubuntu下载vscode并运行程序_第5张图片
设置偏好。随意设置,也可以默认不设置ubuntu下载vscode并运行程序_第6张图片

vscode配置

安装g++

在终端输入

sudo apt-get install vim
sudo apt install g++

安装g++
ubuntu下载vscode并运行程序_第7张图片
ubuntu下载vscode并运行程序_第8张图片

安装中文版

安装好后打开code软件,最左侧的五个标识分别为:
资源管理器;搜索;源代码管理;运行与调试;扩展
我们选择扩展,在搜索框中输入Chinese,点击安装简化版本
ubuntu下载vscode并运行程序_第9张图片
安装好后重新打开code App,软件汉化成功
ubuntu下载vscode并运行程序_第10张图片

安装c++

同样在扩展下,输入c++ ,安装
ubuntu下载vscode并运行程序_第11张图片

在系统的文件夹下创建code文件夹,用vscode软件 打开
ubuntu下载vscode并运行程序_第12张图片

运行测试代码

创建main.cpp


#include
using namespace std;
 
int main()
{
 
  cout <<"hello vscode"<<endl;
  system("pause");
  return 0;
  }

运行一下选择g++,会生成launch.json和task.json,同时报错。
ubuntu下载vscode并运行程序_第13张图片

修改launch和task文件

我们修改这两个文件。
Launch文件全部修改如下


// An highlighted block
{
    // 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,
        "MIMode": "gdb",
        "preLaunchTask": "build",
        "setupCommands": [
            {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
            }
        ]
    }
    ]
}

task全部修改如下

{
    // 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"]
    }
    ]
}

保存,重新运行。按F5或者点击上方菜单栏的运行。

ubuntu下载vscode并运行程序_第14张图片
运行成功,生成**.out**文件 和main文件
ubuntu下载vscode并运行程序_第15张图片
如有帮助点赞收藏关注!
如需转载请注明出处!
本文参考链接:传送门

你可能感兴趣的:(ubuntu,c++,计算机视觉,ubuntu,vscode,linux)