I am using Visual Studio Code in my C++ project. I installed Microsoft C/C++ Extension for VS Code. I got the following error:
#include errors detected. Please update your includePath. IntelliSense features for this translation unit (
/path/to/project/file.cpp) will be provided by the Tag Parser.
asked Aug 9, 2017 at 6:50
![]()
3
Close and re-open Visual Studio Code.
![]()
answered Oct 13, 2018 at 19:38
Ivy GrowingIvy Growing
2,2502 gold badges16 silver badges22 bronze badges
4
The answer is here: How to use C/Cpp extension and add includepath to configurations.
Click the light bulb and then edit the JSON file which is opened. Choose the right block corresponding to your platform (there are Mac, Linux, Win32 – ms-vscode.cpptools version: 3). Update paths in includePath (matters if you compile with VS Code) or browse.paths (matters if you navigate with VS Code) or both.
Thanks to @Francesco Borzì, I will append his answer here:
You have to Left 🖰 click on the bulb next to the squiggled code line.
If a
#includefile or one of its dependencies cannot be found, you can also click on the red squiggles under the include statements to view suggestions for how to update your configuration.

answered Aug 9, 2017 at 6:51
![]()
banan3’14banan3’14
3,3333 gold badges22 silver badges45 bronze badges
8
If you are working with cmake-tools and the error messages says something is wrong with the configurationProvider, then you have 2 options:
- Use
ms-vscode.cpptoolsinstead ofms-vscode.cmake-tools - Define the headers in
CMakeLists.txt
Option 1: Use ms-vscode.cpptools instead of ms-vscode.cmake-tools.
- Open c_cpp_properties.json. (windows key on windows or cmd key on mac + shift + p, enter «c/c++ edit configurations» and chose ‘json’.
- Enter ms-vscode.cpptools as value for configurationProvider instead of ms-vscode.cmake-tools or whatever you have.
How it should look like after the replacement of configurationProvider:

One other important configuration is the include path. The assumption is that you have this configuration right. May be like following

Option 2: Define the headers in CMakeLists.txt
When configurationProvider is set to ms-vscode.cmake-tools in c_cpp_properties.json, VS Code uses the include information defined in the CMakeLists.txt instead of reading the includePath configs in VS Code.
So you need to setup the include path correctly:
- using the include_directories command (rather than the target_include_directories command) to define the headers
- Configure the project to reflect the change happened in the previous step.
mckelvin
3,7701 gold badge28 silver badges22 bronze badges
answered Jun 26, 2021 at 6:07
5
- Left mouse click on the bulb of error line
- Click
Edit Include path - Then this window popup

- Just set
Compiler path
answered May 31, 2020 at 6:51
![]()
akashakash
7075 silver badges12 bronze badges
3
I ended up here after struggling for a while, but actually what I was missing was just:
If a #include file or one of its dependencies cannot be found, you can also click on the red squiggles under the include statements to view suggestions for how to update your configuration.

source: https://code.visualstudio.com/docs/languages/cpp#_intellisense
answered Jan 8, 2019 at 22:14
Francesco BorziFrancesco Borzi
53.2k46 gold badges170 silver badges242 bronze badges
2
The error message «Please update your includePath» does not necessarily mean there is actually a problem with the includePath. The problem may be that VSCode is using the wrong compiler or wrong IntelliSense mode. I have written instructions in this answer on how to troubleshoot and align your VSCode C++ configuration with your compiler and project.
answered Aug 31, 2019 at 23:18
Scott McPeakScott McPeak
7,4182 gold badges37 silver badges67 bronze badges
0
I was trying a hello world program, and this line:
#include <stdio.h>
was underlined green. I tried:
- Deleting the line
- Re-writing the line
- Clicking the yellow bulb and choosing to update
fixed the error warning. i don’t know if it fixed the actual problem. But then i’m compiling via a linux VM on Windows 10
answered Sep 20, 2017 at 12:14
![]()
Zach SmithZach Smith
8,11713 gold badges56 silver badges127 bronze badges
0
I’m on a Macbook M1 Pro, and I had red squiggly error lines all over my C++ files. To solve, I did this:
- Open Preferences -> Settings
- Search for
intelliSenseEngine - Change «C_Cpp: Intelli Sense Engine» from
DefaulttoTag Parser
alternatively, you could create a .vscode folder in your project root, and then create a settings.json with the content of
{
"C_Cpp.intelliSenseEngine" : "Tag Parser"
}
ideally, you should have a c_cpp_properties.json file in the same folder with the right settings as well.
Note: I got this idea from Github here.
![]()
answered Oct 2, 2022 at 8:37
![]()
Go to your c_cpp_properties.json file by searching from settings.There you might see the following code
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
Change the compiler path as below
"compilerPath": "/usr/bin/g++",
answered Mar 7, 2021 at 19:10
![]()
Sihat AfnanSihat Afnan
6956 silver badges14 bronze badges
1
After closing and reopening VS, this should resolve.
answered Aug 9, 2019 at 20:59
![]()
PatrickPatrick
991 silver badge2 bronze badges
If someone have this problem, maybe you just have to install build-essential.
apt install build-essential
answered May 21, 2020 at 0:27
PickiPicki
4594 silver badges10 bronze badges
For me, using Ubuntu, I just had to install gcc to solve this issue.
sudo apt install gcc
Then, set the compiler path to gcc. Go to your c_cpp_properties.json file, set:
"compilerPath": "/usr/bin/gcc"
answered Mar 8, 2021 at 20:17
![]()
An alternative answer would be opening VS Code in remote WSL, if you going to compile files with g++. Just close your VS Code and open WSL and type code . After that the File Explorer shows that VS Code is now running in the context of WSL with the title bar [WSL: Ubuntu]. But make sure you’d installed the GNU compiler tools and the GDB debugger on WSL.
source: https://code.visualstudio.com/docs/cpp/config-wsl
answered Jul 4, 2021 at 8:53
- For Windows:
1.Install Mingw-w64
2.Then Edit environment variables for your account «C:mingw-w64x86_64-8.1.0-win32-seh-rt_v6-rev0mingw64bin»
3.Reload
-
For MAC
1.Open search ,command + shift +P, and run this code “c/c++ edit configurations (ui)”
2.open file c_cpp_properties.json and update the includePath from «${workspaceFolder}/**» to «${workspaceFolder}/inc»
answered Mar 18, 2020 at 14:31
![]()
In my case I did not need to close the whole VS-Code, closing the opened file (and sometimes even saving it) solved the issue.
answered Oct 21, 2020 at 8:17
![]()
My header file was in include/head.h, code in src/code.cpp. I wrote
#include "head.h"
and got this error. Changing it to
#include "../include/head.h"
fixed it.
answered Mar 16, 2022 at 22:06
![]()
Alex LiAlex Li
2434 silver badges11 bronze badges
2
I solved this problem, once I removed configurationProvider node and set
cStandard and cppStandard to default values:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}",
"${workspaceFolder}/**",
"${workspaceFolder}/test",
"/opt/qt5/include/QtCore",
"${workspaceFolder}/test"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}
answered Aug 23, 2022 at 11:06
![]()
after you install the c/c++ extension, two files are created inside .vscode folder.
open c_cpp_properties.json file and paste this key-value pair inside configuration object.(if it doesn’t already exists)
"configurationProvider": "ms-vscode-cpptools"
if it does already exists in the object, see if the value part is ms-vscode-cmaketools. if such it is, replace that existing line with above line.
this will allow you to execute your cpp files along with c files.
answered Nov 2, 2022 at 13:42
I solved the error on my Mac by just clicking on the Edit «include path settings» and changing the compiler path to /usr/bin/clang.
![]()
banan3’14
3,3333 gold badges22 silver badges45 bronze badges
answered Dec 2, 2022 at 17:29
![]()
For Windows:
- Please add this directory to your environment variable(Path):
C:mingw-w64x86_64-8.1.0-win32-seh-rt_v6-rev0mingw64bin
- For Include errors detected, mention the path of your include folder into
«includePath»: [
«C:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/include/» ]
, as this is the path from where the compiler fetches the library to be included in your program.
answered Apr 4, 2020 at 8:30
In case you’ve copied and pasted code into your new file in VS Code
Please delete #include <iostream> and try to build again.
![]()
banan3’14
3,3333 gold badges22 silver badges45 bronze badges
answered Dec 10, 2021 at 15:35
1
Hello, so I am new to coding and wanted to use VS Code to code in C++, so I installed it, installed C/C++ IntelliSense v0.12.4 and followed instructions on the VS Code website to make a c_cpp_properties.json file and copied the code into it like they said. When I open my .cpp project that I had made in notepad++, I get the error:
«#include errors detected. Please update your includePath. IntelliSense features for this translation unit (directoryfile.cpp) will be provided by the Tag Parser. (9, 1)
cannot open source file «iostream» (9, 1)»
My .cpp code
`#include
using namespace std;
int main()
{
string firstName, lastName;
double hourRate, numHours;
cout << "+----------------------------------------+" << endl;
cout << " Your first name and last name: ";
cin >> firstName >> lastName;
cout << " Your hourly rate: ";
cin >> hourRate;
cout << " Number of hours worked last week: ";
cin >> numHours;
cout << endl;
double regPay, overTPay, gPay, socSec, med, netPay;
if (numHours <= 40)
{
regPay = hourRate * numHours;
gPay = regPay;
overTPay = 0;
}
else
{
double oTHours;
oTHours = numHours - 40;
regPay = hourRate * (numHours - (numHours - 40));
overTPay = (hourRate * 1.5) * oTHours;
gPay = regPay + overTPay;
}
socSec = gPay * 0.062;
med = gPay * 0.0145;
netPay = gPay - (socSec + med);
cout << "+----------------------------------------+" << endl << endl;
cout << " Pay Stubn" << " Regular pay $" << regPay << endl;
cout << " Overtime pay $" << overTPay << endl;
cout << " Gross pay $" << gPay << endl;
cout << " Social Sec. $" << socSec << endl;
cout << " Medicare $" << med << endl;
cout << " Net Pay $" << netPay << endl << endl;
cout << "+----------------------------------------+" << endl << endl;
cout << " Pay to: " << firstName << " " << lastName << endl;
cout << " Total Pay: $" << netPay << endl << "ttt ";
cout << "Signed: P inc." << endl;
cout << "+----------------------------------------+" << endl;
return 0;
}`
My c_cpp_properties.json file
{
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
]
},
{
"name": "Linux",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "Win32",
"includePath": [
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++",
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 3
}
Also, when I hover over the «» this shows up:
«#include errors detected. Please update your includePath. IntelliSense features for this translation unit (E:StuffCS11-ThingsHomeworksA3paycheck.cpp) will be provided by the Tag Parser.
cannot open source file «iostream»»
Let me know if you need any more information
In c++ project when you have included header file, but inside project we are not able to access that header file then generally we get error for cannot open source file. For fixing this error check that included file is available in project include path or not.
cannot open source file visual studio C++
Solution-1 : Check your Visual Studio Project settings under C++, Check Include directories and make sure Your_filename.h is pointing to correct path. After adding proper include directories it will resolve cannot open source file visual studio error.

You can right click to header file and open from visual studio. If file is pointing properly it will open.

If your include file is not properly pointing or you have not added inside your included directory then you will not able to open from visual studio.

Solution-2 : Another solution, If your header file is at different folder/location then you can include file path directly in header file. Here you can use relative path or you can provide full path of header file.
Include based on your project folder structure and requirement.
#include "../FolderName/filename.h" OR #include "./FolderName/filename.h" OR #include "FullPath/filename.h"
Solution-1: iostream file opening error normally comes when we are missing $(IncludePath) inside Properties->VC++ Directories->Include Directories. And you have by mistake removed Include path.
Solution-2: Other possible reason is that during installing Visual studio you did not selected c++ packages.
Solution-3: You can check by including stdafx.h in starting (only for Visual studio projects)
#include "stdafx.h" #include <iostream> using namespace std;
Solution-4: Sometimes these type of error comes when multiple Visual Studio versions are install in single PC. You can check Projects and Solutions –> VC++ Directories, are properly added for your project and pointing to correct version location.
For Visual Studio Code:
c++ cannot open source file iostream in visual studio code can also occurs when proper paths are not added inside visual studio code c_cpp_properties.json file.
Mode details:
https://code.visualstudio.com/docs/cpp/config-msvc#_prerequisites
cannot open source file “string”
Try below steps to resolve error.
1) Open VC++ Directories option inside Configuration Properties of visual studio
2) Her all directories value (e.g. Executable directories) will be available, just you need to select drop-down and click edit
3) Remove selection of Inherit from parent
4) Now just click OK and you will see no changes inside Edit box.
5) You need to repeat this thing for all directories, At the end executable directories will be set to $(ExecutablePath) and Include directories will be set to $(IncludePath), similar way to all directories
6)Now click apply and then OK
Conclusion for cannot open source file c++
We have provided solutions for multiple errors for can not open source file c++, If you try given solution hopefully you will able to resolve error. But if still you are getting error you can add your comment and code. We will try to resolve and find solution for you. Happy coding 🙂
Reader Interactions
Hello, so I am new to coding and wanted to use VS Code to code in C++, so I installed it, installed C/C++ IntelliSense v0.12.4 and followed instructions on the VS Code website to make a c_cpp_properties.json file and copied the code into it like they said. When I open my .cpp project that I had made in notepad++, I get the error:
«#include errors detected. Please update your includePath. IntelliSense features for this translation unit (directoryfile.cpp) will be provided by the Tag Parser. (9, 1)
cannot open source file «iostream» (9, 1)»
My .cpp code
`#include
using namespace std;
int main()
{
string firstName, lastName;
double hourRate, numHours;
cout << "+----------------------------------------+" << endl;
cout << " Your first name and last name: ";
cin >> firstName >> lastName;
cout << " Your hourly rate: ";
cin >> hourRate;
cout << " Number of hours worked last week: ";
cin >> numHours;
cout << endl;
double regPay, overTPay, gPay, socSec, med, netPay;
if (numHours <= 40)
{
regPay = hourRate * numHours;
gPay = regPay;
overTPay = 0;
}
else
{
double oTHours;
oTHours = numHours - 40;
regPay = hourRate * (numHours - (numHours - 40));
overTPay = (hourRate * 1.5) * oTHours;
gPay = regPay + overTPay;
}
socSec = gPay * 0.062;
med = gPay * 0.0145;
netPay = gPay - (socSec + med);
cout << "+----------------------------------------+" << endl << endl;
cout << " Pay Stubn" << " Regular pay $" << regPay << endl;
cout << " Overtime pay $" << overTPay << endl;
cout << " Gross pay $" << gPay << endl;
cout << " Social Sec. $" << socSec << endl;
cout << " Medicare $" << med << endl;
cout << " Net Pay $" << netPay << endl << endl;
cout << "+----------------------------------------+" << endl << endl;
cout << " Pay to: " << firstName << " " << lastName << endl;
cout << " Total Pay: $" << netPay << endl << "ttt ";
cout << "Signed: P inc." << endl;
cout << "+----------------------------------------+" << endl;
return 0;
}`
My c_cpp_properties.json file
{
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
]
},
{
"name": "Linux",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "Win32",
"includePath": [
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++",
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 3
}
Also, when I hover over the «» this shows up:
«#include errors detected. Please update your includePath. IntelliSense features for this translation unit (E:StuffCS11-ThingsHomeworksA3paycheck.cpp) will be provided by the Tag Parser.
cannot open source file «iostream»»
Let me know if you need any more information