不知道为什么| 开车不能穿什么鞋| 禁忌什么意思| 米线是什么做的| 先知是什么意思| 不粘锅涂层是什么材料| 曲安奈德针治疗什么| 示字旁与什么有关| 梦见死尸什么预兆| 发烧感冒挂什么科室| 1996年属什么| 负压是什么意思| 女人肾虚吃什么好得快| wba是什么意思| 佛跳墙是什么| 2019属什么生肖| 什么是腔梗| 肩胛骨疼痛挂什么科| 什么叫结节| 起风疹了用什么快速方法能解决| 谋杀是什么意思| 牙齿痛吃什么药| 代发是什么意思| 一级军士长什么级别| 鸡拉绿色粪便吃什么药| 什么地散步| 宫颈疼是什么原因| 热淋是什么意思| 梦见蛇蛋是什么意思啊| 屁是什么气体| 沙发是什么头发| 什么螺不能吃| 大便出血是什么原因| 月经推迟一个月不来什么原因| 熬夜有什么危害| 肝囊性灶是什么意思| 迪奥什么意思| 五十坐地能吸土是什么意思| 女生下面什么样| 孕妇心情不好对胎儿有什么影响| 怀才不遇是什么意思| 总蛋白低是什么意思| 睡几个小时就醒了是什么原因| 分水岭是什么意思| 梦到活人死了是什么预兆| 追什么| 非无菌是什么意思| 肾结石能吃什么| 副市长什么级别| 手背发黄是什么原因| 中医师承是什么意思| 威士忌属于什么酒| 李子不能和什么一起吃| 直接胆红素是什么| 结婚婚检都检查什么项目| 破鞋是什么意思啊| 肺部ct挂什么科| 处女座男和什么星座最配| 尿液发黄是什么原因| 查传染病四项挂什么科| 六月初六是什么节| 上升星座代表什么| 腰痛是什么原因引起的| 平均血小板体积偏低是什么意思| 优对什么| 贵人相助是什么意思| 吃海参有什么好处| 2038年是什么年| 下眼睑跳动是什么原因| 八月十日是什么星座| 英雄的动物是什么生肖| 党参有什么功效| 什么烟最好抽| 补办医保卡去什么地方| 呓语是什么意思| 宫颈纳氏囊肿是什么| 口干咽干是什么原因| 吃生葵花籽有什么好处和坏处吗| 什么叫非萎缩性胃炎| 小孩为什么吃果糖二磷酸钠| gjb2基因杂合突变是什么意思| 鹤是什么生肖| 职称有什么用| 白芍的功效与作用是什么| 吃了安宫牛黄丸要禁忌什么不能吃| 佛爷是什么意思| 脚心痒是什么原因| 现充什么意思| 塔罗是什么| 1970年属什么生肖| 垂爱是什么意思| 2月什么星座的| 老有眼屎是什么原因| 2012年属什么生肖| 蓝色加红色是什么颜色| 中单是什么| 什么像什么什么| 6542是什么药| 小儿风寒感冒吃什么药最好| 至是什么意思| 为什么吃甲鱼不吃乌龟| 看胸挂什么科| 热淋是什么病| 嘴里苦是什么原因| 姜黄粉是什么做的| 抑郁症的表现是什么| 舰长是什么级别| 什么时候大阅兵| 五级士官是什么级别| 梦见悬崖峭壁是什么意思| 老人脚浮肿是什么原因引起的| 中暑是什么意思| 尿管痒是什么原因| 梦见自己爬山是什么意思| 暴龙眼镜什么档次| 中国为什么叫中国| 什么的雪人| 为什么手上会起小水泡| 缺钾吃什么药| 细胞器是什么| 梅毒会通过什么传染| 眼睛疲劳干涩用什么眼药水| 蝎子吃什么食物| 咲是什么意思| 痰多咳嗽是什么原因| 胃烧心吃什么能缓解| trust什么意思| 白带是什么颜色| 鼻咽部淋巴组织增生是什么意思| 行李为什么叫行李| 什么是慢性病| 三什么一什么四字词语| 什么是甲减有什么症状| 25属什么生肖| 宫颈糜烂有什么症状和现象| 杜鹃花什么时候开花| 小儿流鼻涕吃什么药好| 喜悦之情溢于言表什么意思| 什么首什么尾| 美味佳肴是什么意思| 淘米水洗脸有什么好处| 眉毛变白是什么原因| 温度计里面红色液体是什么| 血沉是检查什么的| 心肌炎做什么检查| 酒店尾房是什么意思| 艾灸后痒是什么原因| 今年什么生肖年| 早上八点到九点属于什么时辰| 肝脏不好吃什么食物才能养肝护肝| 许嵩的粉丝叫什么| 氟利昂是什么| 浣碧什么时候背叛甄嬛| 肌肉劳损吃什么药| 途字五行属什么| 全血是什么| 手足口吃什么药| 毛细血管扩张是什么原因引起的| 槐花什么时候开花| 天麻种植需要什么条件| 执业药师是干什么的| 浸润性癌是什么意思| 什么的大圆盘| 化疗之后吃什么好| 开封有什么好玩的地方| 青梅竹马是什么意思| 铁饱和度低什么原因| 甲状腺不均质改变是什么意思| 证明是什么意思| 颈动脉斑块挂什么科| 心脏跳动过快吃什么药| 丙型肝炎病毒抗体阴性什么意思| 打喷嚏头疼是什么原因| 引流是什么意思| 火字旁有什么字| 人有三急指的是什么| 绿色的鸟是什么鸟| 山茱萸是什么| 杠杆是什么意思| 为什么会长痘| 淋巴结肿大吃什么食物好| 六一送女孩子什么礼物| 什么样的女人不能娶| 中医七情指的是什么| 亚麻籽是什么| 益气养阴是什么意思| 孕期心情不好对胎儿有什么影响| 妇炎康片主要治什么妇科病| 今夕何夕什么意思| 水代表什么数字| 甜五行属什么| 小强是什么意思| 破鞋是什么意思啊| 风寒感冒吃什么药最快| 细菌性阴道病用什么药| 男人手大代表什么| 陈皮是什么| 中暑是什么症状表现| 特异性是什么意思| 天空为什么会下雨| 经期洗头有什么危害| 阴虱病是什么原因引起的| 左眼跳是什么意思| 30岁以上适合用什么牌子的护肤品| 吐气如兰是什么意思| 枭念什么| 宫颈糜烂用什么药好| 五七干校是什么意思| 一冷就咳嗽是什么原因| 月光像什么| 北极有什么动物| 男人本色是什么意思| 胚根发育成什么| 腐竹和什么一起炒好吃| 食管反流用什么药效果好| 来月经吃什么排得最干净| 检查糖尿病挂什么科| 4月出生是什么星座| 早上起床口苦口干是什么原因| 铅是什么东西| 坐围和臀围有什么区别| 七月二十四是什么星座| 老年骨质疏松疼痛有什么好疗法| 闪亮的什么| 一字千金是什么生肖| 红烧肉配什么菜好吃| 甲木是什么意思| 小猫不能吃什么| 蚰蜒是什么| 早上流鼻血是什么原因| 1026什么星座| 肉松可以做什么美食| 孕妇梦见西瓜是什么意思| 伽马射线是什么| 感冒为什么会鼻塞| 心虚是什么意思| 喉咙痛可以吃什么水果| 水牛背满月脸是什么病| 点解是什么意思| 味淋可以用什么代替| smile是什么牌子| 怀疑肝不好挂什么科室| 龙骨为什么比排骨便宜| 蛇的天敌是什么动物| 小肠火吃什么药| 无量寿佛是什么意思| 怀孕六个月出血是什么原因| 腹股沟黑是什么原因| 膳食纤维是什么| 寅时是什么时间| 卡鱼刺挂什么科| 小五行属性是什么| 月经三个月没来是什么原因| 世界上最大的沙漠是什么沙漠| 两肺间质性改变是什么意思| 707是什么意思| 梦见一群羊是什么意思| 梦游的人为什么不能叫醒| 所向披靡是什么意思| 牛肉炒什么| 香港什么东西值得买| 以什么乱什么| 牛肉和什么包饺子好吃| 红月亮是什么兆头| 百度

Try to extend agent mode in VS Code!

关爱退役军人就是支持国防事业

百度   为保证交通安全,测试道路都选在五环以外,避开住宅区、办公区、医院、学校等人流量车流量集中的区域。

In this tutorial, you configure Visual Studio Code on macOS to use the Clang/LLVM compiler and debugger.

After configuring VS Code, you will compile and debug a C++ program in VS Code. This tutorial does not teach you about Clang or the C++ language. For those subjects, there are many good resources available on the Web.

If you have any trouble, feel free to file an issue for this tutorial in the VS Code documentation repository.

Prerequisites

To successfully complete this tutorial, you must do the following steps:

  1. Install Visual Studio Code on macOS.

  2. Install the C++ extension for VS Code. You can install the C/C++ extension by searching for 'C++' in the Extensions view (??X (Windows, Linux Ctrl+Shift+X)).

    C/C++ extension

Ensure Clang is installed

Clang might already be installed on your Mac. To verify that it is, open a macOS Terminal window and enter the following command:

clang --version

If Clang isn't installed, enter the following command to install the command line developer tools, which include Clang:

xcode-select --install

Create Hello World app

From the macOS Terminal, create an empty folder called projects where you can store all your VS Code projects, then create a subfolder called helloworld, navigate into it, and open VS Code in that folder by entering the following commands in the terminal window:

mkdir projects
cd projects
mkdir helloworld
cd helloworld
code .

The code . command opens VS Code in the current working folder, which becomes your "workspace". As you go through the tutorial, three files are created in the .vscode folder in your workspace:

  • tasks.json (compiler build settings)
  • launch.json (debugger settings)
  • c_cpp_properties.json (compiler path and IntelliSense settings)

Add a hello world source code file

In the File Explorer title bar, select the New File button and name the file helloworld.cpp.

New File title bar button

Paste in the following source code:

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};

    for (const string& word : msg)
    {
        cout << word << " ";
    }
    cout << endl;
}

Now press ?S (Windows, Linux Ctrl+S) to save the file. Notice that your files are listed in the File Explorer view (??E (Windows, Linux Ctrl+Shift+E)) in the side bar of VS Code:

File Explorer

You can also enable Auto Save to automatically save your file changes, by selecting File > Auto Save. You can find out more about the other views in the VS Code User Interface documentation.

Note: When you save or open a C++ file, you may see a notification from the C/C++ extension about the availability of an Insiders version, which lets you test new features and fixes. You can ignore this notification by selecting the X (Clear Notification).

Explore IntelliSense

IntelliSense is a tool to help you code faster and more efficiently by adding code editing features such as code completion, parameter info, quick info, and member lists.

To see IntelliSense in action, hover over vector or string to see their type information. If you type msg. in line 10, you can see a completion list of recommended member functions to call, all generated by IntelliSense:

Statement completion IntelliSense

You can press the Tab key to insert the selected member. Then, when you add the opening parenthesis, information about arguments that the function requires is displayed.

If IntelliSense is not already configured, open the Command Palette (??P (Windows, Linux Ctrl+Shift+P)) and enter Select IntelliSense Configuration. From the dropdown of compilers, select Use clang++ to configure. More information can be found in the IntelliSense configuration documentation.

Run helloworld.cpp

Remember, the C++ extension uses the C++ compiler you installed on your machine to build your program. Make sure you have a C++ compiler, such as Clang, installed before attempting to run and debug helloworld.cpp in VS Code.

  1. Open helloworld.cpp so that it is the active file.

  2. Press the play button in the top right corner of the editor.

    Screenshot of helloworld.cpp and play button

  3. Choose C/C++: clang++ build and debug active file from the list of detected compilers on your system.

    Build and debug task

You are only asked to choose a compiler the first time you run helloworld.cpp. This compiler is the "default" compiler set in tasks.json file.

  1. After the build succeeds, your program's output will appear in the integrated Debug Console.

    screenshot of program output

Congratulations! You've just run your first C++ program in VS Code!

Understanding tasks.json

The first time you run your program, the C++ extension creates tasks.json, located in your project's .vscode folder. tasks.json stores build configurations.

Here is a sample of a tasks.json file on macOS:

{
  "tasks": [
    {
      "type": "cppbuild",
      "label": "C/C++: clang++ build active file",
      "command": "/usr/bin/clang++",
      "args": [
        "-fcolor-diagnostics",
        "-fansi-escape-codes",
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": ["$gcc"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "Task generated by Debugger."
    }
  ],
  "version": "2.0.0"
}

Note: You can learn more about tasks.json variables in the variables reference.

The command setting specifies the program to run. In this case, that isclang++.

The args array specifies the command-line arguments that are passed to clang++. These arguments must be specified in the order expected by the compiler.

This task tells the C++ compiler to take the active file (${file}), compile it, and create an output file (-o switch) in the current directory (${fileDirname}) with the same name as the active file but without the file extension (${fileBasenameNoExtension}). This process creates helloworld.

The label value is what you see in the tasks list, which is based on your personal preference.

The detail value is the description of the task in the tasks list. Update this string to differentiate it from similar tasks.

The problemMatcher value selects the output parser to use for finding errors and warnings in the compiler output. For clang++, the $gcc problem matcher creates the best results.

From now on, the play button always reads from tasks.json to figure out how to build and run your program. You can define multiple build tasks in tasks.json, and whichever task is marked as the default is the one used by the play button. In case you need to change the default compiler, you can run Tasks: Configure Default Build Task in the Command Palette. Alternatively you can modify the tasks.json file and remove the default by replacing this segment:

    "group": {
        "kind": "build",
        "isDefault": true
    },

with this:

    "group": "build",

Modifying tasks.json

You can modify your tasks.json to build multiple C++ files by using an argument like "${workspaceFolder}/*.cpp" instead of "${file}". This builds all .cpp files in your current folder. You can also modify the output filename by replacing "${fileDirname}/${fileBasenameNoExtension}" with a hard-coded filename (for example "${workspaceFolder}/myProgram.out").

Debug helloworld.cpp

To debug your code,

  1. Go back to helloworld.cpp so that it is the active file.

  2. Set a breakpoint by clicking on the editor margin or using F9 on the current line.

    screenshot of breakpoint in helloworld.cpp

  3. From the drop-down next to the play button, select Debug C/C++ File.

    Screenshot of play button drop-down

  4. Choose C/C++: clang++ build and debug active file from the list of detected compilers on your system (you'll only be asked to choose a compiler the first time you run or debug helloworld.cpp).

    Build and debug task

  5. You will see the task execute and print out the output to the Terminal window.

    Hello World Terminal Output

The play button has two modes: Run C/C++ File and Debug C/C++ File. The default is the last-used mode. If you see the debug icon in the play button, you can select the play button to debug, instead of selecting the drop-down menu item.

Explore the debugger

Before you start stepping through the code, let's take a moment to notice several changes in the user interface:

  • The Integrated Terminal appears at the bottom of the source code editor. In the Debug Console tab, you see output that indicates the debugger is up and running.

  • The editor highlights the line where you set a breakpoint before starting the debugger:

    Initial breakpoint

  • The Run and Debug view in the Activity Bar shows debugging information.

  • At the top of the code editor, a debugging control panel appears. You can move this around the screen by grabbing the dots on the left side.

    Debugging controls

Step through the code

Now you're ready to start stepping through the code.

  1. Select the Step over icon in the debugging control panel so that the for (const string& word : msg) statement is highlighted.

    Step over button

    The Step Over command skips over all the internal function calls within the vector and string classes that are invoked when the msg variable is created and initialized. Notice the change in the Variables window. The contents of msg are visible because that statement has completed.

  2. Press Step over again to advance to the next statement (skipping over all the internal code that is executed to initialize the loop). Now, the Variables window shows information about the loop variable.

  3. Press Step over again to execute the cout statement.

  4. If you like, you can keep pressing Step over until all the words in the vector have been printed to the console. But if you are curious, try pressing the Step Into button to step through source code in the C++ standard library!

Set a watch

You might want to keep track of the value of a variable as your program executes. You can do this by setting a watch on the variable.

  1. In the Watch window, select the plus sign and type word in the text box. This is the name of the loop variable. Now view the Watch window as you step through the loop.

    Watch window

    Note: the value of the watch variable is only available when the program execution is within the scope of the variable. For example, for a loop variable, the value is only available when the program is executing the loop.

  2. Add another watch by adding this statement before the loop: int i = 0;. Then, inside the loop, add this statement: ++i;. Now add a watch for i as you did in the previous step.

  3. You can hover over any variable with the mouse pointer while execution is paused to quickly view its value.

    Mouse hover

Customize debugging with launch.json

When you debug with the play button or F5, the C++ extension creates a dynamic debug configuration on the fly.

There are cases where you'd want to customize your debug configuration, such as specifying arguments to pass to the program at runtime. You can define custom debug configurations in a launch.json file.

To create launch.json, choose Add Debug Configuration from the play button drop-down menu.

Add debug configuration play button menu

You'll then see a dropdown for various predefined debugging configurations. Choose C/C++: clang++ build and debug active file. C++ debug configuration dropdown

VS Code creates a launch.json file, which looks something like this:

{
  "configurations": [
    {
      "name": "C/C++: clang++ build and debug active file",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${fileDirname}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "lldb",
      "preLaunchTask": "C/C++: clang++ build active file"
    }
  ],
  "version": "2.0.0"
}

The program setting specifies the program you want to debug. Here it is set to the active file folder ${fileDirname} and active filename ${fileBasenameNoExtension}, which if helloworld.cpp is the active file will be helloworld. The args property is an array of arguments to pass to the program at runtime.

By default, the C++ extension does not add any breakpoints to your source code and the stopAtEntry value is set to false.

Change the stopAtEntry value to true to cause the debugger to stop on the main method when you start debugging.

Ensure that the preLaunchTask value matches the label of the build task in the tasks.json file.

From now on, the play button and F5 will read from your launch.json file when launching your program for debugging.

Adding additional C/C++ settings

For more control over the C/C++ extension, create a c_cpp_properties.json file, which allows you to change settings such as the path to the compiler, include paths, which C++ standard to compile against (such as C++17), and more.

View the C/C++ configuration UI by running the command C/C++: Edit Configurations (UI) from the Command Palette (??P (Windows, Linux Ctrl+Shift+P)).

Command Palette

This opens the C/C++ Configurations page.

C++ configuration

Visual Studio Code places these settings in .vscode/c_cpp_properties.json. If you open that file directly, it should look something like this:

{
  "configurations": [
    {
      "name": "Mac",
      "includePath": ["${workspaceFolder}/**"],
      "defines": [],
      "macFrameworkPath": [
        "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
      ],
      "compilerPath": "/usr/bin/clang",
      "cStandard": "c11",
      "cppStandard": "c++17",
      "intelliSenseMode": "macos-clang-arm64"
    }
  ],
  "version": 4
}

You only need to modify the Include path setting if your program includes header files that are not in your workspace or the standard library path.

Compiler path

The extension uses the compilerPath setting to infer the path to the C++ standard library header files. When the extension knows where to find those files, it can provide features like smart completions and Go to Definition navigation.

The C/C++ extension attempts to populate compilerPath with the default compiler location based on what it finds on your system. The compilerPath search order is:

  • Your PATH for the names of known compilers. The order the compilers appear in the list depends on your PATH.
  • Then hard-coded Xcode paths are searched, such as /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/

For more information, see the IntelliSense configuration documentation.

Mac framework path

On the C/C++ Configuration screen, scroll down and expand Advanced Settings and ensure that Mac framework path points to the system header files. For example: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks

Troubleshooting

Compiler and linking errors

The most common cause of errors (such as undefined _main, or attempting to link with file built for unknown-unsupported file format, and so on) occurs when helloworld.cpp is not the active file when you start a build or start debugging. This is because the compiler is trying to compile something that isn't source code, like your launch.json, tasks.json, or c_cpp_properties.json file.

If you see build errors mentioning "C++11 extensions", you might not have updated your tasks.json build task to use the clang++ argument --std=c++17. By default, clang++ uses the C++98 standard, which doesn't support the initialization used in helloworld.cpp. Make sure to replace the entire contents of your tasks.json file with the code block provided in the Run helloworld.cpp section.

Terminal won't launch for input

On macOS Catalina and onwards, you might have the issue where you are unable to enter input, even after setting "externalConsole": true. A terminal window opens, but it does not actually allow you to type any input.

The issue is currently tracked #5079.

The workaround is to have VS Code launch the terminal once. You can do this by adding and running this task in your tasks.json:

{
  "label": "Open Terminal",
  "type": "shell",
  "command": "osascript -e 'tell application \"Terminal\"\ndo script \"echo hello\"\nend tell'",
  "problemMatcher": []
}

You can run this specific task using Terminal > Run Task... and select Open Terminal.

Once you accept the permission request, then the external console should appear when you debug.

Next steps

身上红痣多是什么原因 少字五行属什么 果脯是什么东西 尿里有潜血是什么原因 办理港澳通行证需要什么材料
阴历六月十五是什么日子 心颤是什么症状 01年属什么的 干什么能挣钱快 七八年属什么生肖
2009年是什么生肖 中药学专业学什么 为什么半夜流鼻血 眼睛无神呆滞什么原因 老当益壮是什么意思
什么叫基因突变 万箭穿心是什么意思 豪情万丈什么意思 什么是情商 rv是什么意思
鼻炎吃什么药hcv8jop5ns2r.cn 固精是什么意思hcv9jop8ns0r.cn 做梦梦到狗是什么征兆hcv9jop1ns3r.cn 何五行属性是什么hcv7jop5ns0r.cn 一年级又什么又什么hcv9jop0ns9r.cn
直销是什么意思wzqsfys.com cos是什么hcv9jop1ns5r.cn 老狐狸是什么意思hcv9jop6ns0r.cn 矫正视力什么意思cl108k.com 长期开灯睡觉有什么危害hcv8jop8ns5r.cn
发烧感冒吃什么药hcv8jop4ns6r.cn 打破伤风不能吃什么hcv7jop6ns4r.cn c12是什么hcv8jop4ns1r.cn 第一颗原子弹叫什么hcv8jop0ns8r.cn serum是什么意思hcv7jop4ns7r.cn
狮子座什么星象hcv8jop5ns5r.cn 送什么礼物给孩子bfb118.com 猫需要打什么疫苗hcv8jop0ns6r.cn 可转债是什么hcv8jop5ns3r.cn 牙齿变黑是什么原因hcv8jop7ns7r.cn
百度