检测到 #include 错误。请更新 includePath。已为此翻译单元(/Users/zhoujianwen.cn/works/github/test/test.cpp)禁用波形曲线。C/C++(1696)
无法打开 源 文件 “wchar.h” (dependency of “iostream”)C/C++(1696)![在这里插入图片描述](https://img-blog.csdnimg.cn/20200824192850205.png#pic_left)
g++ -v -E -x c++ -
输出的路径信息
按下command + shift + p , 选择C/C++编辑配置(JSON)
将刚才输出的路径信息拷贝到c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.1/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
],
"defines": [],
"macFrameworkPath": [],
"compilerPath": "/usr/local/bin/gcc-8",
"cStandard": "c11",
"cppStandard": "gnu++14",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
保存即可生效。
如何编译和调试代码?
首先要配置好c_cpp_properties、launch、settings、tasks等 json 文件,其中 settings 是自动创建的,不用管它。
command + shift + p
c_cpp_properties.json
自动在当前目录下创建.vscode 文件夹,并创建c_cpp_properties.json,而其它的json配置文件创建方法类似,当然也可以手动创建,然后打开文件点击配置自动构建。
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3/include",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"defines": [],
"macFrameworkPath": [],
"compilerPath": "/usr/local/bin/gcc-8",
"cStandard": "c11",
"cppStandard": "gnu++14",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
tasks.json![在这里插入图片描述](https://img-blog.csdnimg.cn/20200825170024457.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3pob3Vtb29u,size_16,color_FFFFFF,t_70#pic_left)
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}","-std=c++11"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
launch.json![在这里插入图片描述](https://img-blog.csdnimg.cn/20200825170156908.png#pic_left) ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200825170249786.png#pic_left)
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "C/C++: g++ build active file"
}
]
}
在当前目录新建一个operatorfile.cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define st_mtime st_mtimespec.tv_sec
void statfile()
{
struct stat st;
if(-1 == stat("./test.txt",&st)) //获取文件状态
{
cout |