我正在尝试在 Visual Studio Community 2017 上构建解决方案,但我不断收到错误“ 无法打开包含文件:'stdio.h' ”。我已经阅读了几个类似的问题,但仍然无法解决这个问题。看起来 stdio.h 文件在 stdafx.h 文件中被调用。以下是更多详细信息。有什么建议么? (我还不能嵌入图片,所以请点击链接查看截图。)

系统详情:
视窗 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 步: 我点击了 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 ==========

故障排除细节/我尝试过的事情:
  • 配置属性 > 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>#include "stdafx.h" 下方都有红色波浪线,并表示“无法打开源文件”。
    尝试:我尝试删除最后两行,但后来出现了更多错误。
  • 尝试:由于许多人建议不需要 stdafx.h,我尝试只删除第一行 0x251812231343141 。但为了让这个工作,我不得不做更多的事情。 请参阅下面的答案。
  • 最佳答案

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

    关于c++ - 无法打开包含文件 : 'stdio.h' - Visual Studio Community 2017 - C++ Error,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44219901/

    10-14 19:38
    查看更多