我想在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