Visual studio code include path not working c++
Setting up Include Path in Visual Studio Code for C++
- Open Your C++ Project in Visual Studio Code
Ensure that your C++ project is opened in Visual Studio Code.
- Create a tasks.json File
Create a tasks.json file in the .vscode directory of your project if it doesn't already exist.
- Add the Compiler Path to tasks.json
Inside tasks.json, add the path to your C++ compiler under the "version" field. For example:
json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
- Create a c_cpp_properties.json File
Create a c_cpp_properties.json file in the .vscode directory of your project if it doesn't already exist.
- Configure Include Path in c_cpp_properties.json
Inside c_cpp_properties.json, configure the includePath to include the necessary directories. For example:
json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/",
"C:/path/to/your/include/folder"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/path/to/your/compiler",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
- Save the Files
Save the tasks.json and c_cpp_properties.json files.
- Restart Visual Studio Code
After making these changes, restart Visual Studio Code for the changes to take effect.