命名空间std的一个有关问题
命名空间std的一个问题!
#include <limits>
#include <iostream>
using std::cout;
using std::endl;
using std::numeric_limits;
int main(){
cout<<"The range for type short is from "
<<numeric_limits<short>::min()
<<" to "
<<numeric_limits<short>::max();
return 0;
}
程序报错numeric_limits<short>' : is not a class or namespace name
可是如果改写一下
cout<<"The range for type short is from "
<<std::numeric_limits<short>::min()
<<" to "
<<std::numeric_limits<short>::max();
加上std:: 就没问题了,编译,链接都可以。
这是为什么呢?我明明已经using std::numeric_limits;如果numeric_limits不是std空间的,那么我加上std::numeric_limits<>应该也没用才对啊!
这是怎么回事啊?
------解决方案--------------------
using std::numeric_limits不是命名空间,把
using std::cout;
using std::endl;
using std::numeric_limits;
改为
using namespace std;
#include <limits>
#include <iostream>
using std::cout;
using std::endl;
using std::numeric_limits;
int main(){
cout<<"The range for type short is from "
<<numeric_limits<short>::min()
<<" to "
<<numeric_limits<short>::max();
return 0;
}
程序报错numeric_limits<short>' : is not a class or namespace name
可是如果改写一下
cout<<"The range for type short is from "
<<std::numeric_limits<short>::min()
<<" to "
<<std::numeric_limits<short>::max();
加上std:: 就没问题了,编译,链接都可以。
这是为什么呢?我明明已经using std::numeric_limits;如果numeric_limits不是std空间的,那么我加上std::numeric_limits<>应该也没用才对啊!
这是怎么回事啊?
------解决方案--------------------
using std::numeric_limits不是命名空间,把
using std::cout;
using std::endl;
using std::numeric_limits;
改为
using namespace std;