9
votes

I just want to try c++ coding with Visual Studio code. I have installed vscode 1.18.1 to my laptop (Win10-64).

I got errors by typing following code:

#include <iostream>
using namespace std;
int main()
{
    std::cout << "Hello world!" <<endl;
    return 0;
}

Should happen no Error. C:\Users\Harri\OneDrive\Tiedostot\Demo2.vscode\c_cpp_properties.json -content:

"path": [ "/usr/include", "/usr/local/include", "${workspaceRoot}" ],

Problems/Errors for row 1:

" #include errors detected. Please update your includePath. IntelliSense features for this translation unit (C:\Users\Harri\OneDrive\Tiedostot\Demo2\Calc.cpp) will be provided by the Tag Parser. "

" cannot open source file "iostream" "

1
An Extension Ms-C/C++ (ms-vscode.cpptools) is installedMr72
Could somone much more wiser help me with the Windows PATH problems to the vscode Extensions? The current path only define: CMD>>PATH= ...;C:\Program Files\Microsoft VS Code\bin Extensions are located on the C:\Program Files\Microsoft VS Code\resources\app\extensions -folder, I think. Windows search: %USERPROFILE%\.vscode\extensions Does not found the correct path.Mr72

1 Answers

0
votes

The main problem is cygwin paths

You have cygwin paths like /usr/include in your c_cpp_properties.json file. That is a problem because VSCode does not understand cygwin paths. At a cygwin shell you can run:

  $ cygpath -w /usr/include
  D:\cygwin64\usr\include

to get the equivalent Windows path. Put that into c_cpp_properties.json instead. Remember that you have to double the backslashes when you copy this into a JSON string.

Other suggestions

This SO answer describes how to set up VSCode with cygwin gcc. I haven't tried those instructions but they look reasonable.

Beyond that, I highly recommend going through the Get Started with C++ tutorial on the VSCode site. It might directly answer your question, but even if it doesn't, having a working setup to compare to is valuable.

Also, look at the C/C++ diagnostics: View → Command Palette... → C/C++: Log Diagnostics. This will show things like which compiler VSCode is trying to emulate and what it thinks the #include paths are.

Finally, to get lots of useful information directly from your compiler to compare with what VSCode thinks, if you are using gcc, run at a cygwin or bash prompt:

  $ touch empty.c
  $ gcc -v -E -dD empty.c > compiler-info.txt

That will write to compiler-info.txt all the predefined macros, #include search paths, default target, etc.