Ubuntu下安装并配置VS Code编译C++

《Ubuntu下安装并配置VS Code编译C++》要点:
本文介绍了Ubuntu下安装并配置VS Code编译C++,希望对您有用。如果有疑问,可以联系我们。

网上看了很多教程,写的都不细致,或者我理解不够透彻,一步一步操作下来,总是差错百出.好不容易成功一次,现将完整过程记录如下

安装VS Code

sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make
sudo apt-get update
sudo apt-get install ubuntu-make
sudo umake web visual-studio-code

然后按a直接默认批准就可以.

安装插件

打开VS Code后,按crtl + shift + P调出命令行,然后搜索C++,安装微软本身开发的那个.
同样可以安装C++ Intellisense插件,用于自动补全代码.

配置launch.json和tasks.json

注意VS Code只能打开源码所在的文件夹,而不是直接打开源码文件,不然下面将无法进行!

打开源码地点文件夹后,在该文件夹中打开源码.按F5键,选择C++,

Ubuntu下安装并配置VS Code编译C++

然后会自动生成launch.json文件,下面只必要修改两个地方

"program": "enter program name,for example \${workspaceRoot}/a.out",

改为

"program": "${workspaceRoot}/a.out",

"cwd": "\${workspaceRoot}",

改为

"cwd": "${workspaceRoot}",

完备的launch.json

{
    "version": "0.2.0","configurations": [
        {
            "name": "(gdb) Launch","type": "cppdbg","request": "launch","program": "${workspaceRoot}/a.out","args": [],"stopAtEntry": false,"cwd": "${workspaceRoot}","environment": [],"externalConsole": true,"MIMode": "gdb","setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true
                }
            ]
        }
    ]
}

然后,调出敕令行,输入Task Runner,选择others

Ubuntu下安装并配置VS Code编译C++



此时将自动生成tasks.json
将此中的

"command": "echo",

改为

"command": "g++",

"args": ["Hello World"],

改为

注意这里的main.cpp要和你当前路径的源码名称同等.
完整的tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0","command": "g++","isShellCommand": true,"args": ["-g","${workspaceRoot}/main.cpp"],"showOutput": "always"
}

运行测试

随意编写个代码

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

按crtl + shift + B构建,按F5运行,发现终端一闪而过,什么都没有输出.于是考虑Windows下的方法.

#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
    cout<<"hello VS Code"<<endl;
    system("pause");
    return 0;
}

同样并没有卵用.那就换一种方式.

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    cout<<"hello VS Code"<<endl;
    getchar();
    return 0;
}

按crtl + shift + B构建,法式完美输出.有图为证,哈哈

Ubuntu下安装并配置VS Code编译C++

跋文:
期间在终端里执行了以下操作

sudo apt-get install clang

如果提示Clang有错可以运行该敕令,安装clang.

那么问题来了,是不是换个文件夹每次写个代码都得设置装备摆设lauch.json和task.json文件呢?或者将.vscode文件夹复制到当前文件夹下?这样岂不是很麻烦,细思极恐.

Ubuntu 14.04 安装Visual Studio Code  http://www.linuxidc.com/Linux/2016-03/129052.htm

使用Visual Studio Code开发TypeScript  http://www.linuxidc.com/Linux/2015-07/119456.htm

Visual Studio Code 简单试用体验  http://www.linuxidc.com/Linux/2015-05/116887.htm

Visual Studio Code试用体验  http://www.linuxidc.com/Linux/2015-07/120378.htm

Visual Studio 2010 & Help Library Manager 安装阐明 http://www.linuxidc.com/Linux/2012-11/74814.htm

OpenCV 2.3.x/2.4.x在Visual Studio 2005/2008和Visual Studio 2010配置办法详解 http://www.linuxidc.com/Linux/2012-08/68302.htm

使用OpenCV-2.4.0.exe文件编译x86或x64平台Visual Studio 2005/2008/2010目的文件 http://www.linuxidc.com/Linux/2012-08/68305.htm

Visual Studio LightSwitch增加���HTML5和JavaScript的支持 http://www.linuxidc.com/Linux/2012-06/63397.htm

Visual Studio 11:使用 C++ 开发一个最简单的 Metro 利用 http://www.linuxidc.com/Linux/2012-06/62657.htm

Ubuntu 14.04若何安装Visual studio Code  http://www.linuxidc.com/Linux/2016-07/132886.htm

Visual Studio 的详细先容:请点这里
Visual Studio 的下载地址:请点这里

本文永远更新链接地址:http://www.linuxidc.com/Linux/2017-06/145113.htm

linux

欢迎参与《Ubuntu下安装并配置VS Code编译C++》讨论,分享您的想法,编程之家PHP学院为您提供专业教程。

相关文章

文章浏览阅读1.3k次。在 Redis 中,键(Keys)是非常重要的概...
文章浏览阅读3.3k次,点赞44次,收藏88次。本篇是对单节点的...
文章浏览阅读8.4k次,点赞8次,收藏18次。Spring Boot 整合R...
文章浏览阅读978次,点赞25次,收藏21次。在Centos上安装Red...
文章浏览阅读1.2k次,点赞21次,收藏22次。Docker-Compose部...
文章浏览阅读2.2k次,点赞59次,收藏38次。合理的JedisPool资...