我正在尝试在Visual Studio Community 2017上构建解决方案,但是一直出现错误:“无法打开包括文件:'stdio.h'”。
我已经阅读了几个类似的问题,但还是无法解决这个问题。看起来stdio.h文件是在stdafx.h文件中调用的。以下是更多详细信息。有什么建议吗?
系统详细信息:
- Windows 10
- Visual Studio Community 2017 v.15.2 (26430.6) - 安装了C++桌面开发工具包 (截图:安装列表)
步骤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++目录
包含目录 $(VC_IncludePath);$(WindowsSDK_IncludePath);
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>
注意:在
<stdio.h>
和<tchar.h>
的#include
下都有红色波浪线,并显示“无法打开源文件”。尝试过:我尝试删除最后两行,但是接着出现了更多错误。
尝试过:由于许多人建议不需要使用stdafx.h,我尝试仅删除第一行
#include "stdafx.h"
。但为了使其正常工作,我需要进行一些额外的操作。请参见下面的答案。
#include "stdafx.h"
。我需要做更多的事情,这也是我认为 @manni66 建议的。首先,我按照此处的说明设置了忽略预编译标头的选项。然后,我从代码中删除了那一行。感谢大家的意见! - dahiana#include <cstdio>
。 - Thomas Matthews