需要先安裝window SDK
**windows.h頭文件的位置通常位于[Windows Kits](https://www.baidu.com/s?sa=re_dqa_generate&wd=Windows%20Kits&rsv_pq=826ce39d000a376b&oq=window%20sdk%20%E5%A4%B4%E6%96%87%E4%BB%B6%20windows.h%20%E5%9C%A8%E5%93%AA%E9%87%8C&rsv_t=0eccxBhreAvLKpb4c5Pz5pBO7Vlm7qSMlzSPgleqaZ0/Fn1oqhP66ugGx/iOBuVZt6o&tn=98010089_dg&ie=utf-8)的Include目錄下。** 例如悼泌,在64位系統(tǒng)上午衰,windows.h的位置可能為:
* **Windows 7 SDK**:`C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include`
* **Windows 8 SDK**:`C:\Program Files (x86)\Windows Kits\8.0\Include\um`
* **Windows 8.1 SDK**:`C:\Program Files (x86)\Windows Kits\8.1\Include\um`
* **Windows 10 SDK**:`C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um`
這些路徑可能會根據(jù)你安裝的[Windows Kit](https://www.baidu.com/s?sa=re_dqa_generate&wd=Windows%20Kit&rsv_pq=826ce39d000a376b&oq=window%20sdk%20%E5%A4%B4%E6%96%87%E4%BB%B6%20windows.h%20%E5%9C%A8%E5%93%AA%E9%87%8C&rsv_t=0eccxBhreAvLKpb4c5Pz5pBO7Vlm7qSMlzSPgleqaZ0/Fn1oqhP66ugGx/iOBuVZt6o&tn=98010089_dg&ie=utf-8)版本有所不同颈渊。如果你在使用[Visual Studio](https://www.baidu.com/s?sa=re_dqa_generate&wd=Visual%20Studio&rsv_pq=826ce39d000a376b&oq=window%20sdk%20%E5%A4%B4%E6%96%87%E4%BB%B6%20windows.h%20%E5%9C%A8%E5%93%AA%E9%87%8C&rsv_t=0eccxBhreAvLKpb4c5Pz5pBO7Vlm7qSMlzSPgleqaZ0/Fn1oqhP66ugGx/iOBuVZt6o&tn=98010089_dg&ie=utf-8)時遇到找不到windows.h的問題垂谢,可以按照以下步驟解決:
1. **檢查[項目屬性](https://www.baidu.com/s?sa=re_dqa_generate&wd=%E9%A1%B9%E7%9B%AE%E5%B1%9E%E6%80%A7&rsv_pq=826ce39d000a376b&oq=window%20sdk%20%E5%A4%B4%E6%96%87%E4%BB%B6%20windows.h%20%E5%9C%A8%E5%93%AA%E9%87%8C&rsv_t=0eccxBhreAvLKpb4c5Pz5pBO7Vlm7qSMlzSPgleqaZ0/Fn1oqhP66ugGx/iOBuVZt6o&tn=98010089_dg&ie=utf-8)**:右鍵點擊項目 -> 屬性 -> 配置屬性 -> 常規(guī)家坎,確保Windows SDK版本選擇的是你已安裝的版本型宙。
2. **調(diào)整包含目錄**:在屬性頁的VC++目錄 -> 包含目錄中添加相應的路徑撬呢,例如 `C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um`。
通過以上步驟妆兑,你應該能夠找到并正確引用windows.h頭文件魂拦。
配置
.vscode\c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
// 這是window sdk路徑
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/um",
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:/huanjing/mingw64/bin/gcc.exe",
"intelliSenseMode": "gcc-x64"
},
{
"name": "C++",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:/huanjing/mingw64/bin/g++.exe"
}
],
"version": 4
}
.vscode\launch.json
{
// 使用 IntelliSense 了解相關(guān)屬性。
// 懸停以查看現(xiàn)有屬性的描述搁嗓。
// 欲了解更多信息芯勘,請訪問: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 啟動 C++",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:/huanjing/mingw64/bin/gdb.exe",
"setupCommands": [
{
"description": "為 gdb 啟用整齊打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "將反匯編風格設(shè)置為 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
.vscode\tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe 生成活動文件",
"command": "D:/huanjing/mingw64/bin/gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:/huanjing/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "編譯器: D:/huanjing/mingw64/bin/gcc.exe"
}
]
}