문제 설명
VSCode(Mac) 2020의 C++ std_lib_facilities.h 파일 (C++ std_lib_facilities.h file in VSCode (Mac) 2020)
저는 프로그래밍 방법을 배우기 시작했습니다. 내 Mac과 C/C++ 확장에 VSCode를 설정했습니다. 나는 Stroustrup의 Programming and Principles 책에서 helloworld 프로그램을 작성했습니다. 내 helloworld.cpp 파일과 같은 폴더에 std_lib_facilities.h 파일을 넣습니다. 여전히 오류 메시지가 나타납니다. #include 오류가 감지되었습니다. includePath를 업데이트하십시오. 이 번역 단위에 대해 물결선이 비활성화되어 있습니다.
왜 여전히 오류가 발생합니까? 책에 따르면 내가 필요한 것은 .cpp 프로그램과 동일한 디렉토리에 std_lib_facilities.h.txt 파일을 저장하는 것뿐입니다. 같은 폴더에 있는데 왜 이 오류가 발생합니까?
내 코드:
#include "std_lib_facilites.h"
int main()
{
cout << "Hello World \n";
return 0;
}
참조 솔루션
방법 1:
First of all, you have a typo in the filename.
#include "std_lib_facilites.h"
It should be std_lib_facilities.h
(source 1, source 2). And make sure to save it as .h
.
Second, you can configure a .vscode/c_cpp_properties.json file to specify the path to the header files. See the VS Code docs for the JSON schema reference.
- Open the Command Palette
- Select "C/C++: Edit Configurations (JSON)"
- Set the
includePath
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/path/to/headers"
],
...
}
],
By default it already has "${workspaceFolder}/**"
which should search for header files in your workspace (and its sub‑folders). But you can also specify paths to other folders.
(by STRICKLAND_7、Gino Mempin)