视觉C++无法打开包含文件"iostream"
Visual C++ can't open include file 'iostream'
我是C++的新手。我刚开始!我在Visual C++2010学习版上尝试了一段代码,但收到了以下代码错误消息。
------生成已启动:项目:abc,配置:调试Win32------ugo.cppc: \users\castle\documents\visual studio 2010\projects\abc\abc\ugo.cpp(3):致命错误C1083:无法打开包含文件:"iostream":没有这样的文件或目录===========生成:0成功,1失败,0最新,0跳过==========
这是代码:
// 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.00n";
cout << "Here we go!n";
return 0;
}
替换
#include <iostream.h>
带有
using namespace std;
#include <iostream>
您应该检查的一些内容:
-
检查Visual Studio版本中的include文件夹(在"C:\Program Files\Microsoft Visual Studio xx.x\VC\include"中,检查要包含的文件
iostream
,确保它在那里)。 -
检查您的项目在<项目名称>→ 属性→ 配置属性→ VC++目录→ 包含目录(应该看起来像这样:
$(VCInstallDir)include;$(VCInstallDir)atlmfcinclude;$(WindowsSdkDir)include;$(FrameworkSDKDir)include;
) -
请确保为此代码选择了正确的项目(菜单文件→ 新建→ 项目→ Visual C++→ Win32控制台应用程序)
-
请确保代码文件中没有
<iostream.h>
,Visual Studio不支持(在同一项目中的,请检查其他代码文件.cpp和.h文件中的<iostream.h>并将其删除)。 -
请确保您没有多个
main() function in your project code files (*in the same project, check your other code files, .cpp and .h files for the*
main()`函数,并将其删除或替换为其他名称)。
一些你可以尝试构建的东西:
- 从
main()
函数中排除using namespace std;
,并将其放在include指令之后 - 使用
std::cout
而不使用using namespace std;
我在Visual Studio 2015中遇到了完全相同的问题。从Visual Studio 2010及更高版本开始,您需要在所有项目中包含#include "stdafx.h"
。
#include "stdafx.h"
#include <iostream>
using namespace std;
上面的对我有效。下面的没有:
#include <iostream>
using namespace std;
这也失败了:
#include <iostream>
using namespace std;
#include "stdafx.h"
您很可能在属性中丢失$(IncludePath)→ VC++目录→ 包括目录。
添加此项将使iostream和其他内容再次可见。您可能在设置程序时错误地删除了它。
如果您的包含目录在VC++项目属性表中被正确引用→ 配置属性→ VC++目录→ 包含目录,路径在宏$(VC_IncludePath)中引用。
在我的Visual Studio 2015中,评估结果为:"C: \Program Files(x86)\Microsoft Visual Studio 14.0\VC\include"
using namespace std;
#include <iostream>
您的编译器和安装在它周围的资源可能不完整。我建议重新安装你的编译器:之后它应该可以工作了。
我在Visual Studio 2015中创建"空"控制台应用程序时遇到此错误。我重新创建了应用程序,未选中"空"框。它添加了所有必要的库。
确保安装了使用C++的桌面开发。
我遇到了同样的问题,因为我只安装了通用Windows平台开发。
Microsoft Visual Studio很有趣。当您使用安装程序时,必须复选许多选项,以绕过.NET框架(在某种程度上)生成更多的C++而不是C#应用程序,例如桌面开发下的CLR选项。。。在Visual Studio安装程序中。。。。区别在于C++Win32控制台项目或C++CLR控制台项目。
那有什么区别呢?好吧,我不打算列出CLR包含的所有文件,但由于大多数好的C++内核都在Linux中。。。因此CLR允许您绕过许多Windows.NET框架,因为VisualStudio实际上是为您准备的用C#制作应用程序。
这是一个C++Win32控制台项目!
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!" << endl;
return 0;
}
现在这里有一个C++CLR控制台项目!
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine("Hello, World!");
return 0;
}
两个程序都做同样的事情。。。。CLR只是看起来更像是框架式的类重载方法,所以微软可以开发出自己的庞大库,如果你愿意的话,你应该熟悉它。
关键词(C++)
为了避免错误,您将从调试中学到其他东西:
#ifdef _MRC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
如果创建了名为IncludePath的环境变量,请尝试将其重命名为其他变量。
此名称将覆盖项目属性内的$(IncludePath)。
小程序的快速修复:
添加:#include <cstdlib>
在我的情况下,我的Visual Studio 2015安装时没有选择C++程序包,而Visual Studio 2017安装时带有C++程序包。如果我使用Visual Studio 2015,打开C++项目将显示此错误,使用Visual Studio 2017将不会出错。
我也遇到了这个问题。我使用了这个代码(在main()之前)在Visual Studio 2022中,并且它变成了OK:
#include "pch.h"
#include <iostream>
using namespace std;
using namespace winrt;
using namespace Windows::Foundation;
错误消息"无法打开源文件iostream";通常发生在C++编译器不能定位标准输入/输出头文件"时;iostream";在编译期间。
若要解决此问题,您可以尝试以下操作:
-
检查是否包含了正确的头文件";iostream";在C++代码中使用#include指令。正确的语法是:
#include <iostream>
-
检查您的系统上是否安装了C++编译器。您可以使用GCC、Clang或Microsoft Visual C++等编译器来编译代码。
-
检查C++编译器的包含路径是否设置正确。包含路径告诉编译器在哪里找到头文件;iostream";。如果路径设置不正确,编译器可能无法找到该文件。
-
如果您使用的是像Visual Studio这样的IDE,请尝试创建一个新项目并将代码复制到其中。这有时可以解决项目设置的问题。
-
如果以上步骤都不起作用,可以尝试重新安装C++编译器或使用其他编译器。
我希望这能帮助你解决这个问题。
// first.cpp -- displays a message
#include <iostream> // a PREPROCESSOR directive
int main() // function header
{ // start of a function body
std::cout << "Come up and C++ me sometime.n"; // message
// start a new line
std::cout << "Here is the total: 1000.00n";
std::cout << "Here we go!n";
return 0;
}
- vcruntime.h 从 Windows 包含文件夹中丢失?
- 禁止显示有关包含文件中 #pragma 包的警告
- 无法打开包含文件:在 vs2017 上'QtWidgets/qtwidgetsglobal.h'
- 包含文件 <sched_yield.h>在我的 RHEL 5 上找不到
- 尝试使用 MSVC 从源代码构建 qt 创建器:无法打开包含文件:"stddef.h":没有这样的文件或目录
- 无法打开包含文件'Graphics.hpp'没有这样的文件或目录,Visual Studio的其他包含不起作用
- 为什么 C++ 编译器在"c:program filesgnu emacsinclude"中查找包含文件?
- 包含文件中的 Typdef "未在此范围内声明"
- 错误: C1083: 无法打开包含文件:"boost/asio.hpp": 没有此类文件或目录
- SFML c ++ 当包含文件内游戏中发生事件时,如何使用铃声函数为我的游戏创建声音类?
- 在Windows上设置CMake和vcpkg时出错"无法打开包含文件"
- 致命错误 C1083:无法打开包含文件:"GL/glew.h":没有此类文件或目录
- Qt自动生成的.rc文件无法打开包含文件'windows.h'
- Visual Studio 停止识别任何包含文件
- 无法打开包含文件:"签证.h"
- 如何检查每个头文件是否包含必需的包含文件?
- Protobuf:无法在 message.pb.h 文件中打开包含文件 common.h
- extern 关键字在包含文件头文件C++
- 错误:无法打开包含文件:"MQTTAsync.h":没有此类文件或目录
- #include "date.h" 创建错误 E1696 无法打开源文件"date.h",也无法打开包含文件:没有这样的文件或目录