最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Ubuntu下安裝并配置VS Code編譯C++的方法

 更新時(shí)間:2018年02月11日 11:20:53   作者:LTQblog  
這篇文章主要介紹了Ubuntu下安裝并配置VS Code編譯C++的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

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直接默認(rèn)同意就可以。

安裝插件

打開(kāi)VS Code后,按crtl + shift + P調(diào)出命令行,然后搜索C++,安裝微軟自己開(kāi)發(fā)的那個(gè)。

同樣可以安裝C++ Intellisense插件,用于自動(dòng)補(bǔ)全代碼。

配置launch.json和tasks.json

注意VS Code只能打開(kāi)源碼所在的文件夾,而不是直接打開(kāi)源碼文件,否則下面將無(wú)法進(jìn)行!

打開(kāi)源碼所在文件夾后,在該文件夾中打開(kāi)源碼。按F5鍵,選擇C++,

然后會(huì)自動(dòng)生成launch.json文件,下面只需要修改兩個(gè)地方

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

然后,調(diào)出命令行,輸入Task Runner,選擇others

 

此時(shí)將自動(dòng)生成tasks.json

將其中的

"command": "echo",

改為

"command": "g++",

"args": ["Hello World"],

改為

"args": ["-g","${workspaceRoot}/main.cpp"],

注意這里的main.cpp要和你當(dāng)前路徑的源碼名稱(chēng)一致。

完整的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"
}

運(yùn)行測(cè)試

隨便編寫(xiě)個(gè)代碼

#include<iostream>
using namespace std;

int main()
{
  cout<<"hello VS Code"<<endl;
  return 0;
}

按crtl + shift + B構(gòu)建,按F5運(yùn)行,發(fā)現(xiàn)終端一閃而過(guò),什么都沒(méi)有輸出。于是考慮Windows下的辦法。

#include<iostream>
#include<stdlib.h>
using namespace std;

int main()
{
  cout<<"hello VS Code"<<endl;
  system("pause");
  return 0;
}

同樣并沒(méi)有卵用。那就換一種方式。

#include<iostream>
#include<stdio.h>
using namespace std;

int main()
{
  cout<<"hello VS Code"<<endl;
  getchar();
  return 0;
}

按crtl + shift + B構(gòu)建,按F5運(yùn)行,程序完美輸出。有圖為證,哈哈

后記:

期間在終端里執(zhí)行了以下操作

sudo apt-get install clang

如果提示Clang有錯(cuò)可以運(yùn)行該命令,安裝clang。

那么問(wèn)題來(lái)了,是不是換個(gè)文件夾每次寫(xiě)個(gè)代碼都得配置lauch.json和task.json文件呢?或者將.vscode文件夾復(fù)制到當(dāng)前文件夾下?這樣豈不是很麻煩,細(xì)思極恐

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

岱山县| 阳曲县| 杭锦后旗| 伊金霍洛旗| 溆浦县| 呼玛县| 班戈县| 平定县| 仙游县| 汝城县| 太湖县| 利津县| 栾川县| 华安县| 余干县| 高安市| 马鞍山市| 嘉祥县| 海丰县| 东明县| 海阳市| 固阳县| 秀山| 年辖:市辖区| 静海县| 类乌齐县| 哈巴河县| 临漳县| 嘉鱼县| 鸡西市| 江安县| 莒南县| 锦州市| 耒阳市| 淳安县| 东丽区| 铜鼓县| 瓮安县| 灌南县| 贡嘎县| 台州市|