[c++] Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error

I am trying to Build a Solution on Visual Studio Community 2017, but I keep getting the error "Cannot open include file: 'stdio.h' ". I've read through several similar questions, but still can't fix this problem. Looks like the stdio.h file is called in the stdafx.h file. Below are more details. Any suggestions? (I can't embed images yet, so please click on the links for screenshots.)

System details: Windows 10
Visual Studio Community 2017 v.15.2 (26430.6)
-- Installed Desktop Development with C++ (Screenshot: Installation list)


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;
}

Step 2: I clicked on Build > Build Solution.

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

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 ==========

Troubleshooting details/Things I've tried:

  1. Configuration Properties > VC++ Directories
    Include Directories $(VC_IncludePath);$(WindowsSDK_IncludePath);
  2. Screenshot: Solution Explorer (files in the project)
  3. Code in stdafx.cpp file:

    // 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
    
  4. Code in stdafx.h file:

    // 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>
    

    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.

  5. 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 ANSWER BELOW.

This question is related to c++ visual-studio visual-studio-2017 stdio

The answer is


Similar problem for me but a little different. I can compile and run the default CUDA 10 code with no problem, but there are a lots of error related to the stdio.h file show in the edit window. Which is annoying. I solve it by change the code file name from "kernel.cu" to "kernel.cpp". That is wired but works for me. And it runs well so far.


Faced the problem of missing stdlib.h and stdio.h (and maybe more) after installing VS2017 Community on a new computer and migrating a solution from VS2013 to VS2017.

Used @Maxim Akristiniy's proposal, but still got error message regarding toolset compatibility. However VS itself suggested to do solution retarget by right-clicking on the solution in Solution Explorer, then selecting Retarget solution from the menu and the updated Windows SDK Version from the drop-down list.

Now my projects build w/o a problem.

Note that you may need to make the project your startup project for the retargeting to catch.


Scenario:

  1. Windows 10 with Visual Studio 2017 (FRESH installation).

  2. 'C' project (ERROR like -> cannot open source file: 'stdio.h', 'windows.h', etc.).

Resolve:

  1. Run 'Visual Studio Installer'.

  2. Click button 'Modify'.

  3. Select 'Desktop development with C++'.

  4. From "Installation details"(usually on the right-sidebar) select:

    4.1. Windows 10 SDK(10.0.17134.0).

    • Version of SDK in 4.1. is just for example.
  5. Click button 'Modify', to apply changes.

  6. Right-click 'SomeProject' -> 'Properties'.
  7. 'Configuration:' -> 'All Configurations' and 'Platform:' -> 'All Platforms'.
  8. 'Configuration Properties' -> 'General' -> 'Windows SDK Version':
    • change(select from combobox) SDK version to currently installed;
  9. Click button 'Apply', to apply changes.

I had a similar problem after updating my VS2017. Project built fine; but lots of 'errors' when code was brought up in the editor. Even tried reinstalling VS. I was able to solve it by setting the option “Ignore Standard Include Paths” to Yes. Attempted to build the solution with lots of errors. Went back and set the option to No. After rebuilding, my problem went away.


I had the same problem building VS 2013 Project with Visual Studio 2017 IDE. The solution was to set the right "Platformtoolset v120 (Visual Studio 2013). Therefor there must be the Windows SDK 8.1 installed. If you want to use Platformtoolset v141 (Visual Studio 2017) there must be Windows SDK 10. The Platformtoolset can be chosen inside the properties dialog of the project: General -> Platformtoolset


Faced the same issue, another solution is to add default includes, this fixed the problem for me:

$(IncludePath);

For CUDA:

Right Click on your project.

Go to Properties->CUDA and set "CUDA Toolkit Custom Dir" to your CUDA toolkit directory.

For me it was: C:\\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0

enter image description here


If you run into this problem with Visual Studio 2019 (VS2019), you can download the build tools from https://visualstudio.microsoft.com/downloads/. And, under Tools for Visual Studio 2019 and download Build Tools for Visual Studios 2019.


Got same problem with project porting from VS2013 to VS2017,
Fix: change "Properties->General->Windows SDK Version" to 10


A dirty fix: Add $(VC_IncludePath);$(WindowsSDK_IncludePath); into project Properties / C/C++ / General / Additional include directories


Just in case you don't want to bump Windows SDK to Windows 10 (you could be for example working on an open source project where the decision isn't yours to make), you can solve this problem in a Windows SDK 8.1 project by navigating Tools -> Get Tools and Features... -> Individual Compontents tab and installing the individual components "Windows 8.1 SDK" (under SDKs, libraries and frameworks) and "Windows Universal CRT SDK" (under Compilers, build tools and runtimes):


Examples related to c++

Method Call Chaining; returning a pointer vs a reference? How can I tell if an algorithm is efficient? Difference between opening a file in binary vs text How can compare-and-swap be used for a wait-free mutual exclusion for any shared data structure? Install Qt on Ubuntu #include errors detected in vscode Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio 2017 errors on standard headers How do I check if a Key is pressed on C++

Examples related to visual-studio

VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio? How to download Visual Studio Community Edition 2015 (not 2017) Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio Code pylint: Unable to import 'protorpc' Open the terminal in visual studio? Is Visual Studio Community a 30 day trial? How can I run NUnit tests in Visual Studio 2017? Visual Studio 2017: Display method references

Examples related to visual-studio-2017

Assets file project.assets.json not found. Run a NuGet package restore How to remove an unpushed outgoing commit in Visual Studio? The current .NET SDK does not support targeting .NET Standard 2.0 error in Visual Studio 2017 update 15.3 Create Setup/MSI installer in Visual Studio 2017 VS 2017 Metadata file '.dll could not be found Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error Visual Studio 2017 does not have Business Intelligence Integration Services/Projects How can I run NUnit tests in Visual Studio 2017? How to integrate SAP Crystal Reports in Visual Studio 2017 Unit Tests not discovered in Visual Studio 2017

Examples related to stdio

Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error GCC fatal error: stdio.h: No such file or directory How can I get an int from stdio in C? Code for printf function in C stdlib and colored output in C 'printf' vs. 'cout' in C++ Unable to open a file with fopen() Detecting EOF in C Rerouting stdin and stdout from C How can you flush a write using a file descriptor?