fatal error C1083 Cannot open include file 'iostream.h' No such file or directory 的解决方法

摘自:教育网-自学之路: http://www.selfroad.com.cn/content.asp?id=82

VC++6.0 中的一段程序,有用到iostream.h中的标准输入输出流,直接用 VS2005编译器编译的时候报错“Cannot open include file: 'iostream.h': No such file or directory”。

旧的源文件如下:

#include
int main()
{

:cout < <"hello world" <

return 0;
}

一直报上面的错误,无法通过编译。

原因和解决方法,如下:

#include 是VC6以前的写法。

#include

using  namespace  std;

这个是标准库的写法。标准库把这些个文件都放到std这个namespace里面了。

可以到VC/include看看和VC6.0的区别,是iostream而不是iostream.h。

注意 和 是两个不同的东西

是STL库

是兼容于c的库

所有STL库都在std::名空间下

std::cout是 里面的对象

namespace std: 所有的C++ Standard Library Class都包含在这个叫std的name

space里。比如 , , 等等。所以当你使用它们其中的class时

,需要加入这个语句,using namespace std; 不然编译器报错。

本例可用两种方法,如下:

方法一:

#include
using spacename std;
int main()
{
  cout < <"hello world" <   return 0;
}

方法二:

#include
int main()
{
  std::cout < <"hello world" <   return 0;
}

以上两种方法修改后的代码就可以在 VS2005 下编译通过

你可能感兴趣的:(fatal error C1083 Cannot open include file 'iostream.h' No such file or directory 的解决方法)