无法打开包含文件:'stdio.h' - Visual Studio Community 2017 - C++ 错误 [英] Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error

查看:261
本文介绍了无法打开包含文件:'stdio.h' - Visual Studio Community 2017 - C++ 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Visual Studio Community 2017 上构建解决方案,但我不断收到错误消息无法打开包含文件:'stdio.h'".

I am trying to build a solution on Visual Studio Community 2017, but I keep getting the error "Cannot open include file: 'stdio.h' ".

我已经阅读了几个类似的问题,但我仍然无法解决这个问题.看起来 stdio.h 文件在 stdafx.h 文件中被调用.以下是更多细节.有什么建议吗?

I've read through several similar questions, but I still can't fix this problem. It looks like the stdio.h file is called in the stdafx.h file. Below are more details. Any suggestions?

系统详情:

  • Windows 10
  • Visual Studio 社区 2017 v.15.2 (26430.6)-- 使用 C++ 安装桌面开发(截图:安装列表)

第 1 步: 我写了著名的 Hello, World! C++ 程序.

Step 1: I wrote the famous Hello, World! program in C++.

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
    cout << "Hello, World!" << endl;
    return 0;
}

第 2 步:我点击了 BuildBuild Solution.

问题: 'stdio.h':没有这样的文件或目录.完全错误:

Problem: 'stdio.h': No such file or directory. Full Error:

1>------ Build started: Project: HelloWorld, Configuration: Debug Win32 ------
1>stdafx.cpp
1>c:usersdahiana minidesktoplearncpphelloworldhelloworldstdafx.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 ==========


故障排除细节和我尝试过的事情:

  1. 配置属性* → 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 下方都有红色波浪线,并说无法打开源文件".

    NOTE: the #include for <stdio.h> and <tchar.h> both have the red squiggle line underneath, and says "cannot open source file".

    尝试:我尝试删除最后两行,但随后出现更多错误.

    Tried: I tried removing the last two lines, but then I got more errors.

    尝试过:由于许多人建议不需要 stdafx.h,因此我尝试仅删除第一行 #include "stdafx.h".但为了让它发挥作用,我必须做更多的事情.请参阅下面的答案.

    Tried: Since many suggested that stdafx.h is not required, I tried removing just the first line, #include "stdafx.h". But in order for this to work I had to do a little more. See the answer below.

    推荐答案

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

    There are three ways to solve this issue.

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

    1. Ignore Precompiled Headers #1
      Steps: Project > Properties > Configuration Properties > C/C++ > Command Line > in the Additional Options box add /Y-. (Screenshot of Property Pages) > Ok > Remove #include "stdafx.h"
    2. Ignore Precompiled Headers #2
      Steps: File > New > Project > ... > In the Application Wizard Window click Next > Uncheck the Precompiled Header box > Finish > Remove #include "stdafx.h"
    3. Reinstall Visual Studio
      This also worked for me, because I realized that maybe there was something wrong with my Windows SDK. I was using Windows 10, but with Windows SDK 8.1. You may have this problem as well.
      Steps: Open Visual Studio Installer > Click on the three-lined Menu Bar > Uninstall > Restart your computer > Open Visual Studio Installer > Install what you want, but make sure you install only the latest Windows SDK 10, not multiple ones nor the 8.1.

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

    The first time I installed Visual Studio, I would get an error stating that I needed to install Windows SDK 8.1. So I did, through Visual Studio Installer's Modify option. Perhaps this was a problem because I was installed it after Visual Studio was already installed, or because I needed SDK 10 instead. Just to be safe I did a complete reinstall.

    这篇关于无法打开包含文件:'stdio.h' - Visual Studio Community 2017 - C++ 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆