C++template问题

来源:百度知道 编辑:UC知道 时间:2024/06/20 10:51:15
#include<iostream>

using namespace std;//这个不能放在下面那句后面
template<typename T>
为什么不能把using namespace std放最后面?这句话中std是什么意思?

using namespace std;中的std 是C++标准名字空间, 一般都放在前面的。
它里面包含了很多函数,输入输出流;比如cout,cin都是它里面的

如果你不用using namespace std,当你使用cout时候,你应该加上std::cout

表示你所使用的cout 是std名空间里所定义的。

template<typename T>
必须放在你定义的地方。所以后面必须跟你定义的东西,如果后面是using namespace std;的话就会有错误的。

这和include一个道理,编译器读代码是从上下往下读,你在中间插一个template<typename T>,打乱代码的顺序,当然会造成错误

standard
建议你详细看一下 名字空间 相关章节