关于c++头文件的问题

来源:百度知道 编辑:UC知道 时间:2024/06/16 18:59:12
#include<iostream.h>
int main(){
string a="我是传奇";
cout<<a;
getchar();
return 0;
}
这个文件在dev-c++里运行是不行的但是如果把头文件换为#include<iostream>
using namespace std;就可以了这两个头文件不是没有区别吗
我做别的程序时是没有这两个区别的
不知这个怎么有

<iostream>和<iostream.h>一样 是标准库的头文件
在某个标准之前,所有头文件都是.h结尾的,也没有名字空间这个东西(namespace)
后来新标准要求,所有标准库头文件都以不带.h的<filename>形式包含,旧的c语言库头文件改为'c'开头,不带.h, 如<stdio.h>改为<cstdio> 等。旧的不再作支持。
但是有些编程环境如vc, borland c , 为了支持老代码,通常提供两种形式给用户使用。
你既可以#include <iostream.h> 也可以 #include<iostream> 然后用 using namespace std; 把所有名字空间std里面的名称倾倒到作用域中。
如果你打开vc的<iostream.h> 可以看到它其实是包含了<iostream>的。

不同编译器的问题吧。
VC++应该是都可以运行的。

这两个应该是没有区别的。

iostream.h是非标准的东西

#include<iostream.h>不是标准库。
参考:
#include<iostream>
using namespace std;
#include<string>
int main()
{
string a="我是传奇";
cout<<a;
return 0;
}

难道dev-c++不包括iostream.h?

因为在c++标准库里是#include "iostream",如果你用的是<>,就要加上using namespace std;