Visual C++ 无法打开包含文件“iostream”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11713842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 15:27:48  来源:igfitidea点击:

Visual c++ can't open include file 'iostream'

c++

提问by jamesbond

I am new to c++. I just started! I tried a code on visual c++ 2010 Express version but i got the following code error message.

我是 C++ 的新手。我刚开始!我在 Visual c++ 2010 Express 版本上尝试了一个代码,但我收到以下代码错误消息。

------ Build started: Project: abc, Configuration: Debug Win32 ------
  ugo.cpp
c:\users\castle\documents\visual studio 2010\projects\abc\abc\ugo.cpp(3): fatal error C1083: Cannot open include file: 'iostream': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This is the code

这是代码

// first.cpp -- displays a message


#include <iostream>   // a PREPROCESSOR directive

int main(void)        // function header
{             // start of a function body
  using namespace std;
  cout << "Come up and C++ me sometime.\n";  // message
  // start a new line
  cout << "Here is the total: 1000.00\n";
  cout << "Here we go!\n";
  return 0;
}

回答by Michael Haephrati

Replace

代替

#include <iostream.h>

with

using namespace std;

#include <iostream>

回答by Secko

Some things that you should check:

您应该检查的一些事项:

  • Check the include folder in your version of VS (in "C:\Program Files\Microsoft Visual Studio xx.x\VC\include" check for the file which you are including, iostream, make sure it's there).

  • Check your projects Include Directoriesin <Project Name> > Properties > Configuration Properties > VC++ Directories > Include Directories- (it should look like this:$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;)

  • Make sure that you selected the correct project for this code (File > New > Project > Visual C++ > Win32 Console Application)

  • Make sure that you don't have <iostream.h>anywhere in your code files, VS doesn't support that (in the same project, check your other code files, .cpp and .h files for<iostream.h>and remove it).

  • Make sure that you don't have more than one main()function in your project code files (in the same project, check your other code files, .cpp and .h files for themain()function and remove it or replace it with another name).

  • 检查您的 VS 版本中的包含文件夹(在“ C:\Program Files\Microsoft Visual Studio xx.x\VC\include”中检查您要包含的文件iostream,确保它在那里)。

  • 检查项目包含目录<Project Name> > Properties > Configuration Properties > VC++ Directories > Include Directories- (它应该是这样的:$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;

  • 确保为此代码选择了正确的项目 ( File > New > Project > Visual C++ > Win32 Console Application)

  • 确保<iostream.h>你的代码文件中没有任何地方,VS 不支持(在同一个项目中,检查你的其他代码文件,.cpp 和 .h 文件<iostream.h>并删除它)。

  • 确保main()您的项目代码文件中没有多个函数(在同一个项目中,检查您的其他代码文件、.cpp 和 .h 文件中的main()函数并将其删除或替换为另一个名称)。

Some things you could try building with:

您可以尝试构建的一些内容:

  • Exclude using namespace std;from your main()function and put it after the include directive.
  • Use std::coutwithout using namespace std;.
  • using namespace std;从您的main()函数中排除并将其放在 include 指令之后。
  • std::cout不使用using namespace std;.

回答by babel17

I had this exact same problem in VS 2015. It looks like as of VS 2010and later you need to include #include "stdafx.h"in all your projects.

我在VS 2015. 看起来VS 2010您需要将其包含#include "stdafx.h"在所有项目中。

#include "stdafx.h"
#include <iostream>
using namespace std;

The above worked for me. The below did not:

以上对我有用。下面没有:

#include <iostream>
using namespace std;

This also failed:

这也失败了:

#include <iostream>
using namespace std;
#include "stdafx.h"

回答by SpicyWeenie

You are more than likely missing $(IncludePath)within Properties->VC++ Directories->Include Directories. Adding this should make iostream and others visible again. You probably deleted it by mistake while setting up your program.

您很可能在属性-> VC++ 目录-> 包含目录中缺少$(IncludePath)。添加这个应该使 iostream 和其他人再次可见。您可能在设置程序时错误地删除了它。

回答by jgdev

I got this error when I created an 'Empty' console application in Visual Studio 2015. I re-created the application, leaving the 'Empty' box unchecked, it added all of the necessary libraries.

我在 Visual Studio 2015 中创建“空”控制台应用程序时遇到此错误。我重新创建了该应用程序,未选中“空”框,它添加了所有必要的库。

回答by Dave

If your include directories are referenced correctly in the VC++ project property sheet -> Configuration Properties -> VC++ directories->Include directories.The path is referenced in the macro $(VC_IncludePath) In my VS 2015 this evaluates to : "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include"

如果在 VC++ 项目属性表中正确引用了包含目录 -> 配置属性 -> VC++ 目录 -> 包含目录。在宏 $(VC_IncludePath) 中引用了路径在我的 VS 2015 中,它的计算结果为:“C:\Program文件 (x86)\Microsoft Visual Studio 14.0\VC\include"

using namespace std;
#include <iostream> 

That did it for me.

那是为我做的。

回答by samantha

Microsoft Visual Studio is funny when your using the installer you MUST checkbox a-lot of options to bypass the .netframework(somewhat) to make more c++ instead of c sharp applications, such as the clr options under dekstop development... in visual studio installer.... difference is c++ win32 console project or a c++ CLR console project. So whats the difference? Well i'm not going to list all of the files CLR includes but since most good c++ kernals are in linux... so CLR allows you to bypass a-lot of the windows .netframework b/c visual studio was really meant for you to make apps in C sharp.

当您使用安装程序时,Microsoft Visual Studio 很有趣,您必须勾选很多选项来绕过 .netframework(有点)以制作更多的 c++ 而不是 c 锐利的应用程序,例如 dekstop 开发下的 clr 选项......在visual studio安装程序.... 区别在于 c++ win32 控制台项目或 c++ CLR 控制台项目。那么有什么区别呢?好吧,我不会列出 CLR 包含的所有文件,但由于大多数优秀的 C++ 内核都在 linux 中......所以 CLR 允许您绕过很多 windows .netframework b/c Visual Studio 真的适合您使应用程序在 C 锐利。

Heres a C++ win32 console project!

这是一个 C++ win32 控制台项目!

#include "stdafx.h"
#include <iostream>
using namespace std;
int main( )
{
cout<<"Hello World"<<endl;
return 0;
}

Now heres a c++ CLR console project!

现在这里有一个 C++ CLR 控制台项目!

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
Console::WriteLine("Hello World");
return 0;
}

Both programs do the same thing .... CLR just looks more frameworked class overloading methodology so microsoft can great it's own vast library you should familiarize yourself w/ if so inclined. https://msdn.microsoft.com/en-us/library/2e6a4at9.aspx

两个程序都做同样的事情.... CLR 只是看起来更加框架化的类重载方法,所以微软可以很好地使用它自己的庞大库,如果你愿意的话,你应该熟悉一下。 https://msdn.microsoft.com/en-us/library/2e6a4at9.aspx

other things you'll learn from debugging to add for error avoidance

你会从调试中学到的其他东西来避免错误

#ifdef _MRC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

回答by Cosine

It is possible that your compiler and the resources installed around it were somehow incomplete. I recommend re-installing your compiler: it should work after that.

您的编译器及其周围安装的资源可能不完整。我建议重新安装您的编译器:之后它应该可以工作。

回答by Stanley

quick fix for small programs:

小程序的快速修复:

add: #include <cstdlib>

添加: #include <cstdlib>

回答by nawab_shazad

    // first.cpp -- displays a message


#include <iostream>   // a PREPROCESSOR directive
using namesapce std;
int main()        // function header
{             // start of a function body
  ///using namespace std;
  cout << "Come up and C++ me sometime.\n";  // message
  // start a new line
  cout << "Here is the total: 1000.00\n";
  cout << "Here we go!\n";
  return 0;
}