C++中include <iostream>和include <iostream.h>的区别
来源:互联网 发布:淘宝网店一件代发货 编辑:程序博客网 时间:2024/04/29 05:23
简单来说: .h的是标准C的头文件,没有.h的是标准C++的头文件,两种都是头文件。 造成这两种形式不同的原因,是C++的发展历史决定的,刚才正好有别的人也问这个问题,这里我再回答一下(注意vs2008和vs2005对标准C++的支持是一样的):
1、以iostream和stdio.h为例,iostream是C++的库,stdio.h是标准C的库。
2、新的C++标准摒弃了.h形式的头文件,所以在vs2005里面是没有iostream.h的头文件的。
3、在早期的vs版本,比如VC6.0,用的还是老版本的C++标准库,例如iostream.h,并且当时标准库也没有引入名字空间。因此直接#include <iostream.h>是可以的。但到了vs2005,使用了新的C++标准库,只能用#include <iostream>。
4、名字空间里可以包含很多东西,比如函数名、标识符、数据类型等等。新的C++标准把标准库中的名字都放入了std名字空间,因此在#include <iostream>之后,还必须使用标准库的名字空间std,才能使用标准库里的类和函数,也就是必须 using namespace std;
5、对于C的标准库,例如,stdio.h,没有名字空间的概念,因此直接包含后即可使用。
6、新的C++标准库为了统一以前的C标准库,将原来c的标准库也放入了std名字空间,并把原来的C标准库去掉了.h后缀,前面加上字母 “c”,例如stdio.h就变成了cstdio,使用时为#include <cstdio>,其内容和#include <stdio.h>相同,但是要额外使用名字空间std,也就是using namespace std;
7、因此,对于新的C++标准库,没有了.h形式的头文件,例如iostream,在包含了头文件以后,必须使用std名字空间才能使用库中的内容。对于C标准库,有两种使用方法,一种是用老的.h形式,例如stdio.h直接包含就可以了;另一种就是用C++的统一形式,例如cstdio,和 C++标准库一样,包含了以后还要加上using namespace std;才能使用。建议采用后面统一的形式,比如你要同时使用C和C++的库,可以这样写:#include <cstdio>#include <iostream>using namespace std;
- C++中include <iostream>和include <iostream.h>的区别
- #include <iostream> 和#include <iostream.h> 以及include " "的区别
- #include<iostream>和#include<iostream.h>的区别
- #include<iostream>和#include<iostream.h>的区别
- #include<iostream>和#include<iostream.h>的区别
- #include<iostream>和#include<iostream.h>的区别
- c++中#include<iostream>、<iostream.h>区别
- C++Primer--->#include<iostream>与#include<iostream.h>以及#inclue<string> 和 #include<string.h>的区别
- #include<iostream.h>与#include "iostream.h"的区别
- #include<iostream>与#include<iostream.h>以及#inclue<string> 和 #include<string.h>的区别
- #include<iostream>与#include<iostream.h>以及#inclue<string> 和 #include<string.h>的区别
- #include<iostream>与#include<iostream.h>及#inclue <string> 和 #include <string.h>的区别
- #include<iostream>与#include<iostream.h>以及#inclue<string> 和 #include<string.h>的区别
- #include<iostream>、#include<iostream.h>和#include<stdio.h>的根本区别
- #include<iostream>和#include<iostream.h>区别使用
- #include<iostream>与#include<iostream.h>的区别
- #include <iostream>与#include <iostream.h>的区别
- #include <iostream>与#include <iostream.h>的区别
- js将弹出的窗口里的js数组返回给父页面
- 青蛙换位置问题----穷尽法实现
- AppStore刷榜那些事儿:猪 也是这么想的
- 学习OpenCV——Kalman滤波
- Linux red hat 5 下tomcat的安装及其环境变量配置 启动
- C++中include <iostream>和include <iostream.h>的区别
- Gtk-WARNING **: 无法在模块路径中找到主题引擎:“pixmap”
- Three20内部实现之随便看看
- 查询学生平均成绩及其名次_24
- Silverlight 转换器应用一修改排充图标显示
- 关于linux环境变量文件
- DEDECMS在任意页面获取任意栏目N级列表链接
- wblogic安装
- 对Photoshop高斯模糊滤镜的算法总结