I am using Programming: Principles and Practice using C++ Third Edition by Bjarne Stroustrup as a self-study resource and am having difficulties getting his custom header and import file to work in VS Code.
The files can be found here. Module PPP and PPP.h
The project is contained in a folder called BSC++ within my /Documents folder. I have downloaded the files referenced above with extensions .h and .ixx and stored them in a folder within the BSC++ folder. Finally, based on some other search results, I added /Users/johnwhite/Documents/BSC++ in the include path section of the C/C++ configuration section.
I’m failing to build and run the following “Hello, World!” program, and it appears from VS Code’s errors that I probably have not correctly configured the C/C++ extension from Microsoft to find and include the header and import files.
All questions and suggestions are welcome.
Program code:#
// This program outputs the message "Hello, World!" to the monitor
import std; // gain access to the C++ standard library
int main() // C++ programs start by executing the function main
{
std::cout<<"Hello, World!n"; // output "Hello, World!"
return 0;
}
Errors from VS Code (4):
[{ "resource": "/Users/johnwhite/Documents/BSC++/Hello.cpp", "owner": "cpptools", "severity": 8, "message": "unknown type name 'import'", "source": "gcc", "startLineNumber": 3, "startColumn": 1, "endLineNumber": 3, "endColumn": 1 }]
[{ "resource": "/Users/johnwhite/Documents/BSC++/Hello.cpp", "owner": "C/C++: IntelliSense", "code": "3275", "severity": 8, "message": "could not find module file for module "std"", "source": "C/C++", "startLineNumber": 3, "startColumn": 8, "endLineNumber": 3, "endColumn": 11 }]
[{ "resource": "/Users/johnwhite/Documents/BSC++/Hello.cpp", "owner": "cpptools", "severity": 8, "message": "'std' is not a class, namespace, or enumeration", "source": "gcc", "startLineNumber": 7, "startColumn": 5, "endLineNumber": 7, "endColumn": 5 }]
[{ "resource": "/Users/johnwhite/Documents/BSC++/Hello.cpp", "owner": "C/C++: IntelliSense", "code": "135", "severity": 8, "message": "namespace "std" has no member "cout"", "source": "C/C++", "startLineNumber": 7, "startColumn": 10, "endLineNumber": 7, "endColumn": 14 }]
I tried to write, build, and run a Hello, World program from Bjarne Stroustrup’s Programming: Principles and Practice using C++ text book.
I expected my code to compile and run. Instead, VS Code kicked out errors about an unknown type and module that could not be found.
John White is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.