标签:命名空间的理解 iosteam与iostream.h的区
C++中为了避免名字定义冲突,特别引入了“名字空间的定义”,即namespace。当代码中用<iostream.h>时,输出可直接引用cout<<x;<iostream.h>继承C语言的标准库文件,未引入名字空间定义,所以可直接使用。
当代码中引入<iostream>时(C++标准),输出需要引用std::cout<<x;如果还是按原来的方法就会有错,或者直接添加using namespace std;
实例:
code1
#include "stdafx.h"
#include <iostream>
using namespace std;
int main(void)
{
	int cout=100;								//cout被覆盖
	cout<<cout;									//整数cout左移100位,不起任何作用
	system("pause");
	return 0;
}code2
#include "stdafx.h"
#include <iostream>
int main(void)
{
	int cout=100;
	std::cout<<cout<<std::endl;		//名字空间中取出函数
	system("pause");
	return 0;
}#include <stdlib.h>
#include <iostream.h>
int main(void)
{
	int a=10;
	cout<<a<<endl;
	int cout=100;		//名字cout被覆盖
	cout<<20;
	system("pause");
	return 0;
}
关于命名空间的理解---iostream与iostream.h的区别,布布扣,bubuko.com
关于命名空间的理解---iostream与iostream.h的区别
标签:命名空间的理解 iosteam与iostream.h的区
原文地址:http://blog.csdn.net/cjc211322/article/details/25864333