无法打开包含文件:'stdio.h' - Visual Studio Community 2017 - C++错误

dah*_*ana 44 c++ stdio visual-studio visual-studio-2017

我正在尝试在Visual Studio社区2017上构建解决方案,但我不断收到错误" 无法打开包含文件:'stdio.h' ".我已经阅读了几个类似的问题,但仍然无法解决这个问题.看起来在stdafx.h文件中调用了stdio.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;
}
Run Code Online (Sandbox Code Playgroud)

第2步:我点击了Build> Build Solution.

问题: '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 ==========
Run Code Online (Sandbox Code Playgroud)

故障排除详细信息/我尝试过的事情:

  1. 配置属性> VC++目录
    Include Directories $(VC_IncludePath);$(WindowsSDK_IncludePath);
  2. 屏幕截图:Solution Explorer(项目中的文件)
  3. 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
    
    Run Code Online (Sandbox Code Playgroud)
  4. 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>
    
    Run Code Online (Sandbox Code Playgroud)

    注意:#includefor <stdio.h><tchar.h>都有下面的红色波浪线,并说"无法打开源文件".
    TRIED:我尝试删除最后两行,但后来我遇到了更多错误.

  5. TRIED:由于许多人建议不要求stdafx.h,我试着删除第一行,#include "stdafx.h".但为了实现这一点,我必须多做一点.请看下面的答案.

Max*_*niy 90

项目从VS2013移植到VS2017时出现同样的问题,
修复:将"属性 - >常规 - > Windows SDK版本"更改为10

  • 这对我有用.谢谢!我还要补充一点,通过右键单击解决方案资源管理器中的项目可以访问这些属性. (7认同)
  • 我还必须按照此处所述安装“Windows Universal CRT SDK”Visual Studio 组件 - /sf/answers/2994465561/ (2认同)

ysa*_*sap 16

在新计算机上安装VS2017社区并将解决方案从VS2013迁移到VS2017之后,面临丢失stdlib.hstdio.h(可能更多)的问题.

使用了@Maxim Akristiniy的提议,但仍然收到有关工具集兼容性的错误消息.但是,VS本身建议通过在解决方案资源管理器中右键单击解决方案来进行解决方案重新定位,然后Retarget solution从菜单中选择并Windows SDK Version从下拉列表中进行更新.

现在我的项目没有问题.

请注意,您可能需要使项目成为重新定位的启动项目.


dah*_*ana 8

有三种方法可以解决这个问题.

  1. 忽略预编译标题#1
    步骤:项目>属性>配置属性> C/C++>命令行>在附加选项框中添加/ Y-.(属性页面的屏幕截图)>确定>删除#include "stdafx.h"
  2. 忽略预编译标题#2
    步骤:文件>新建>项目> ...>在应用程序向导窗口中单击下一步>取消选中预编译标题框>完成>删除#include "stdafx.h"
  3. 重新安装Visual Studio
    这也对我有用,因为我意识到我的Windows SDK可能有问题.我使用的是Windows 10,但使用的是Windows SDK 8.1.你也可能遇到这个问题.
    步骤:打开Visual Studio安装程序>单击三行菜单栏>卸载>重新启动计算机>打开Visual Studio安装程序>安装所需的内容,但请确保仅安装最新的Windows SDK 10,而不是多个,而不是8.1 .

    我第一次安装Visual Studio时,会收到一条错误消息,指出我需要安装Windows SDK 8.1.所以我做了,通过Visual Studio Installer的Modify选项.也许这是一个问题,因为我在安装Visual Studio之后安装了它,或者因为我需要SDK 10.为了安全起见,我做了一个完整的重新安装.


Sap*_*aik 8

对于 CUDA:

右键单击您的项目。

转到Properties->CUDA并将“ CUDA Toolkit Custom Dir ”设置为您的 CUDA toolkit 目录。

对我来说是:C:\\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0

在此处输入图片说明


Hem*_*lle 6

以防万一您不想将 Windows SDK 撞到 Windows 10(例如,您可能正在从事一个不由您做出决定的开源项目),您可以通过以下方式在 Windows SDK 8.1 项目中解决此问题导航Tools -> Get Tools and Features... -> Individual Compontents tab和安装单个组件“Windows 8.1 SDK”(在 SDK、库和框架下)和“Windows Universal CRT SDK”(在编译器、构建工具和运行时下):

  • 除了将 Windows SDK 版本更改为 10 之外,我还必须安装“Windows Universal CRT SDK”Visual Studio 组件。 (3认同)