简体   繁体   中英

Error displaying visual studio code C++

How do I get Visual Studio Code indicates an error in a C++ code?

Installed extensions: С/С++; С/С++ Clang and C++ and C++ Intellisense.

Set the path:

    "name": "Win32",
    "includePath": [
        "D:/programm/MinGW/lib/gcc/mingw32/5.3.0/include/c++"
    ],
    "browse": {
        "limitSymbolsToIncludedHeaders": true,
        "databaseFilename": ""

but errors are not displayed.

In order to get Visual Studio Code indicates errors, create a simple project and use the next VScode configuration:

  1. Install next plugins C/C++ , C/C++ Clang Command Adapter , C++ Intellisense , Easy C++ projects
  2. Open new folder (File -> Open Folder)
  3. Press Ctrl + Shift + P and type Easy Cpp/C++: Create new C++ project
  4. Add the file .vscode\\c_cpp_properties.json with the next content:
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include",
                "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.10150.0\\ucrt"
            ],
            "intelliSenseMode": "msvc-x64",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe",
            "cStandard": "c11",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}
  1. Check out the configuration by pressing F7.

If you see in a terminal the "Hello Easy C++ project!" message, hence the configuration is done. You can easily modify this configuration for your needs.

Possible difficulties:

  • make sure that your configuration has the correct include paths in c_cpp_properties.json
  • if you are using a VisualStudio toolchain, make sure the build.bat file has the right path to the compiler.
  • if you are using clang as a compiler, make sure the clang.executable are set up in a Workspace Settings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM