Visual Studio Code cannot open source file “iostream”

I am new to C++ and Visual Studio Code, so I’m not sure how to fix this issue. I’ve tried to go through the tutorial in Using Clang in Visual Studio Code, but I can’t seem to paste their “Hello, World!” code without the iostream, vector, and string errors.

I’ve also seen posts on here indicating that I should change the includePath string array in configurations, but adding the path to my project folder doesn’t seem to get rid of these errors. I’m at a loss here since everything I’ve seen so far still isn’t working.

The code which causes these errors has been copy pasted directly from the tutorial above:

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

In the first three lines, I’m getting the errors "cannot open source file {the included import's name}". The compiler states that:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/Users/rjc/projects/helloworld/helloworld.cpp).C/C++(1696)

I added this line in my includePath as such (the configurations page states add one includePath per line, so I put these two statements on separate lines):

${workspaceFolder}/**
/Users/rjc/projects/helloworld/

Yet this did not reduce the number of errors. I’m not really sure what to do here, since the tutorial does not seem to be working for me.

I’m running macOS 11.1 (Big Sur) with Clang version 12.0.0. Why do I have these issues?

10

Your includePath only has ${workspaceFolder}. You need to add the path to your system directory. Run this command and make sure all of the paths printed out are listed in your c_cpp_properties.json file: gcc -v -E -x c++ -

9

as told above you should

  • run this command in the terminal: gcc -v -E -x c++ -
  • then it shows you all the paths to include as shown in the image
  • now open search for this file c_cpp_properties.json in vs code (by tapping cntrl + p in vscode)
  • now open c_cpp_properties.json file and paste all the file paths I’ve marked (which may be more or less in your case) as shown in image
  • and then you are ready to go!
  • HAPPY CODING!

1

You only need to change 3 times in the c_cpp_properties.json file.

  1. “name”: “Mac”

  2. add “usr/include/linux” to the “includePath”

  3. “intelliSenseMode”: “clang-x64”

This solution is for Linux users only.

Make sure the compiler in the compilerPath setting exists and that it supports C++.

I saw these stdlib include errors on a (CentOS) system that had GCC installed without C++ support. Installing the missing packaged fixed the errors in Visual Studio Code. Failing to compile a hello.cpp from the terminal made it clear my root problem was not in Visual Studio Code.

On Ubuntu I had different gcc/g++ versions installed.

Check your c++ version

c++ -v

Check directory /usr/include/c++ and if it is missing the corresponding version (10/ or 11/ or 12/), install it sudo apt install libstdc++-XX. I had to install libstdc++-12

sudo apt install libstdc++-12

I am working with mingw g++ compiler. I got this error too while I was runnning my program. I just changed the compiler path. It worked in my case.

1

FWIW, I had a similar issue this week when starting a new cpp project – it turns out that when I had switched from Windows to Linux, midway through kicking off the project, I forgot to update all my paths in the tasks.json and c_cpp_properties.json files (inside the .vscode directory), which were still using the Windows path standards ( instead of /).
Once I fixed this, all was well.
Incidentally, I made my tasks.json an array of tasks and my c_cpp_properties.json an array of configurations as well, allowing me to add both windows compiler options as well as linux compiler options separately – on build I select which one to use.

dont do ctrl + f5! to run the aplication

do ctrl + alt + n

2

I had the same problem, and I was trying anything to get it to work.

Then I realized that when I named the file I only named it helloworld instead of helloworld.cpp behind since this wasn’t needed in the other IDEs I’ve been using.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Visual Studio Code cannot open source file “iostream”

I am new to C++ and Visual Studio Code, so I’m not sure how to fix this issue. I’ve tried to go through the tutorial in Using Clang in Visual Studio Code, but I can’t seem to paste their “Hello, World!” code without the iostream, vector, and string errors.

I’ve also seen posts on here indicating that I should change the includePath string array in configurations, but adding the path to my project folder doesn’t seem to get rid of these errors. I’m at a loss here since everything I’ve seen so far still isn’t working.

The code which causes these errors has been copy pasted directly from the tutorial above:

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

In the first three lines, I’m getting the errors "cannot open source file {the included import's name}". The compiler states that:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/Users/rjc/projects/helloworld/helloworld.cpp).C/C++(1696)

I added this line in my includePath as such (the configurations page states add one includePath per line, so I put these two statements on separate lines):

${workspaceFolder}/**
/Users/rjc/projects/helloworld/

Yet this did not reduce the number of errors. I’m not really sure what to do here, since the tutorial does not seem to be working for me.

I’m running macOS 11.1 (Big Sur) with Clang version 12.0.0. Why do I have these issues?

10

Your includePath only has ${workspaceFolder}. You need to add the path to your system directory. Run this command and make sure all of the paths printed out are listed in your c_cpp_properties.json file: gcc -v -E -x c++ -

9

as told above you should

  • run this command in the terminal: gcc -v -E -x c++ -
  • then it shows you all the paths to include as shown in the image
  • now open search for this file c_cpp_properties.json in vs code (by tapping cntrl + p in vscode)
  • now open c_cpp_properties.json file and paste all the file paths I’ve marked (which may be more or less in your case) as shown in image
  • and then you are ready to go!
  • HAPPY CODING!

1

You only need to change 3 times in the c_cpp_properties.json file.

  1. “name”: “Mac”

  2. add “usr/include/linux” to the “includePath”

  3. “intelliSenseMode”: “clang-x64”

This solution is for Linux users only.

Make sure the compiler in the compilerPath setting exists and that it supports C++.

I saw these stdlib include errors on a (CentOS) system that had GCC installed without C++ support. Installing the missing packaged fixed the errors in Visual Studio Code. Failing to compile a hello.cpp from the terminal made it clear my root problem was not in Visual Studio Code.

On Ubuntu I had different gcc/g++ versions installed.

Check your c++ version

c++ -v

Check directory /usr/include/c++ and if it is missing the corresponding version (10/ or 11/ or 12/), install it sudo apt install libstdc++-XX. I had to install libstdc++-12

sudo apt install libstdc++-12

I am working with mingw g++ compiler. I got this error too while I was runnning my program. I just changed the compiler path. It worked in my case.

1

FWIW, I had a similar issue this week when starting a new cpp project – it turns out that when I had switched from Windows to Linux, midway through kicking off the project, I forgot to update all my paths in the tasks.json and c_cpp_properties.json files (inside the .vscode directory), which were still using the Windows path standards ( instead of /).
Once I fixed this, all was well.
Incidentally, I made my tasks.json an array of tasks and my c_cpp_properties.json an array of configurations as well, allowing me to add both windows compiler options as well as linux compiler options separately – on build I select which one to use.

dont do ctrl + f5! to run the aplication

do ctrl + alt + n

2

I had the same problem, and I was trying anything to get it to work.

Then I realized that when I named the file I only named it helloworld instead of helloworld.cpp behind since this wasn’t needed in the other IDEs I’ve been using.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật