简体   繁体   中英

Visual Studio C++ cannot open some headers I didn't deliberately include

today I wanted to start learning C++. However I keep getting these errors:

Cannot open source file "stdio.h"
Cannot open source file "tchar.h"
Cannot open source file "SDKDDKver.h"

However, I even get these in a default empty win32 console project.

OS: windows 10

My default code looks like this:

    // HelloWorld.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"


    int main()
    {
        return 0;
    }

The errors are:

Severity    Code    Description Project File    Line    Suppression State
Error (active)      cannot open source file "stdio.h"   HelloWorld  c:\Users\HP\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\stdafx.h    10  

Severity    Code    Description Project File    Line    Suppression State
Error (active)      cannot open source file "tchar.h"   HelloWorld  c:\Users\HP\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\stdafx.h    11  

Severity    Code    Description Project File    Line    Suppression State
Error (active)      cannot open source file "SDKDDKVer.h"   HelloWorld  c:\Users\HP\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\targetver.h 8   

Severity    Code    Description Project File    Line    Suppression State
Error (active)      cannot open source file "stdio.h"   HelloWorld  c:\Users\HP\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\stdafx.h    10  

In the OUTPUT window:

1>------ Build started: Project: HelloWorld, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\Win32\PlatformToolsets\v140\Toolset.targets(34,5): error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution".
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

EDIT:

I believe I have C++ installed, cause first when I went to
file > new > project > Visual C++
It would only show me "Install ... for C++", So I installed one of the first options (don't remember which one it was) and after installing it allowed me to create projects.

Check your stdafx.h contents. Headers can be included transitively. In particular, the three ehaders you quote are in the VC++ stdafx.h for new projects. You can simply remove them if you're programming C++.

(It says something about Microsoft's struggle to choose between C and C++ : They don't support C99, but they default to a C header instead of C++. Not even <cstdio> . )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM