我想在Visual Studio Community 2017上構建一個解決方案,但我一直收到錯誤「無法打開包含文件:'stdio。 h'「。我已經閱讀了幾個類似的問題,但仍無法解決這個問題。看起來像stdio.h文件在stdafx.h文件中調用。以下是更多細節。有什麼建議麼? (我不能嵌入圖像還,所以請點擊截圖的鏈接。)無法打開包含文件:'stdio.h' - Visual Studio Community 2017 - C++錯誤
系統細節: 的Windows 10
的Visual Studio 2017年社區v.15.2(26430.6)
- 安裝的桌面開發用C++(Screenshot: Installation list)
第1步:我寫在C著名的Hello World程序++。
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
步驟2:我點擊生成>生成解決方案。
問題:'stdio.h中':沒有這樣的文件或目錄。完全錯誤:
1>------ Build started: Project: HelloWorld, Configuration: Debug Win32 ------
1>stdafx.cpp
1>c:\users\dahiana mini\desktop\learncpp\helloworld\helloworld\stdafx.h(10):
fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory
1>Done building project "HelloWorld.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
故障排除詳細信息/事情我已經嘗試:
- 配置屬性> VC++目錄
Include Directories $(VC_IncludePath);$(WindowsSDK_IncludePath);
- Screenshot: Solution Explorer (files in the project)
守則stdafx.cpp文件:
// stdafx.cpp : source file that includes just the standard includes // HelloWorld.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include "stdafx.h" // TODO: reference any additional headers you need in STDAFX.H // and not in this file
守則stdafx.h中文件:
// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently #pragma once #include "targetver.h" #include <stdio.h> #include <tchar.h>
注:
#include
爲<stdio.h>
和<tchar.h>
都有下方的紅色波浪線線,並說「不能開源文件「。
TRIED:我試圖刪除最後兩行,但後來我得到更多的錯誤。TRIED:由於許多人提示stdafx.h不是必需的,我嘗試刪除第一行
#include "stdafx.h"
。但爲了這個工作,我不得不多做一點。 請看下面的答案。
那麼,首先刪除stdafx.h include,因爲它在VS2017中是非標準和完整的*不必要*。 – DeiDei
禁用預編譯頭並刪除stdafx *。 – 2017-05-27 18:14:06
@DeiDei哦我其實已經試過了。我會在上面添加它。在某種程度上這對我並不適用,因爲我只刪除了這行,'#include「stdafx.h」'。我不得不多做一點,這是我認爲@ manni66的建議。首先,我按照[這裏]的說明(https://docs.microsoft.com/en-us/cpp/build/reference/y-ignore-precompiled-header-options)將我的選項設置爲忽略預編譯頭。然後,我刪除了代碼中的那一行。感謝大家的投入! – dahiana