> For the complete documentation index, see [llms.txt](https://appsecurity.gitbook.io/devops/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://appsecurity.gitbook.io/devops/ppc/ppc-langs/backend/c-c++/ide.md).

# IDE

## VS Code

Устанавливаем расширения:

* C/C++ — ms-vscode.cpptools
* C/C++ Extension Pack — ms-vscode.cpptools-extension-pack

Устанавливаем компилятор для C/C++ — MSVC, GCC или CLang — грубо говоря, в зависимости от ОС (MSVC — Windows, GCC — Unix, CLang — MacOS; конечно, можно исхитриться и настроить любой из них под вашу ОС).

Инструкция для Windows по установке MSVC и пишем первое приложение: <https://code.visualstudio.com/docs/cpp/config-msvc>

### Создание проекта

Важно, чтобы `code .` запускалась из консоли разработчика msvc (`Developer Command Prompt for VS 2022`), иначе VS Code не сможет запустить `cl.exe` компилятор.

```
mkdir my_cpp_project
cd my_cpp_project
code .
```

Создаем файл и пишем код:

```cpp
#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;
}
```

Жмем run и выбираем `cl.exe`.

### Run configuration: tasks.json

После первого запуска VS Code создаст файл `tasks.json`:&#x20;

```json
{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "C/C++: cl.exe build active file",
      "command": "cl.exe",
      "args": [
        "/Zi",
        "/EHsc",
        "/Fe:",
        "${fileDirname}\\${fileBasenameNoExtension}.exe",
        "${file}"
      ],
      "problemMatcher": ["$msCompile"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "Task generated by Debugger."
    }
  ]
}
```

В нем настройки сборки проекта. Подробнее об этом файле <https://code.visualstudio.com/docs/editor/variables-reference>.

Пример уже подправленного конфига (нам надо будет создать директории `bin/debug`, `obj/debug` и `source`):

```json
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "My Debug",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/nologo",
                "/Fe:",
                "${workspaceFolder}\\bin\\debug\\${fileBasenameNoExtension}.exe",
                "/Fd:",
                "${workspaceFolder}\\obj\\debug\\vc140.pdb",
                "/Fo:",
                "${workspaceFolder}\\obj\\debug\\${fileBasenameNoExtension}.obj",
                "${workspaceFolder}\\source\\*.cpp"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Собрать и запустить проект"
        }
    ],
    "version": "2.0.0"
}
```

### Debug configuration: launch.json

Мы смогли запустить код, теперь как подправить конфиг по умолчанию для дебага: жмем на шестеренку сверху справа и выбираем ранее созданную конфигурацию на запуск — создастся файл `launch.json`:

```json
{
    "configurations": [
        
        {
            "name": "C/C++: cl.exe сборка и отладка активного файла",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\bin\\debug\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "console": "externalTerminal",
            "preLaunchTask": "My Debug"
        }
    ],
    "version": "2.0.0"
}
```

### C/C++ Configurations

Если хотим больше контроля над C/C++, создайте конфиг `c_cpp_properties.json`. Это позволит нам менять путь до компилятора, библиотек, выбрать стандарт C++ (по умолчанию это C++17). Жмем `Ctrl+Shift-P` (command palette) и выбираем `C/C++: Edit configurations (UI)`.

### Run VS Code outside Developer Command Prompt

Чтобы не запускать VS Code (code .) из специальной оболочки VS 2022, можно в tasks.json настроить ее автоматическое открытие:

```json
{
    "windows": {
        "options": {
            "shell": {
                "executable": "cmd.exe",
                "args": [
                    "/C",
                    // The path to VsDevCmd.bat depends on the version of Visual Studio you have installed.
                    "\"C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/Common7/Tools/VsDevCmd.bat\"",
                    "&&"
                ]
            }
        }
    },
    "tasks": [
        // ...
    ]
}
```

И добавляем `cl.exe` в `PATH`.

\+ надо добавить библиотеки <https://qna.habr.com/q/475262>

И я не справился: легче запускать VS Code из Developer Command Prompt


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://appsecurity.gitbook.io/devops/ppc/ppc-langs/backend/c-c++/ide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
