注册 登录
编程论坛 C++教室

[求助]请问标准命名空间保存在哪?

华龙 发布于 2007-04-30 18:58, 1048 次点击
总是要using namespace std;可就是不知道这个命名空间定义在哪里?
哪位朋友能够指点一下吗?
6 回复
#2
yuyunliuhen2007-04-30 23:55

你的意思是?
一般情况就不说了,今天查MSDN的时候也看到这个情况
// expre_reinterpret_cast_Operator.cpp
// compile with: /EHsc
#include <iostream>

// Returns a hash code based on an address
unsigned short Hash( void *p ) {
unsigned int val = reinterpret_cast<unsigned int>( p );
return ( unsigned short )( val ^ (val >> 16));
}

using namespace std;
int main() {
int a[20];
for ( int i = 0; i < 20; i++ )
cout << Hash( a + i ) << endl;
}

#3
weishj2007-05-01 13:07

这是俺在MSDN上查到的:
<utility>
namespace std {
// TEMPLATE CLASSES
template<class T, class U>
struct pair;
// TEMPLATE FUNCTIONS
template<class T, class U>
pair<T, U> make_pair(const T& x, const U& y);
template<class T, class U>
bool operator==(const pair<T, U>& x, const pair<T, U>& y);
template<class T, class U>
bool operator!=(const pair<T, U>& x, const pair<T, U>& y);
template<class T, class U>
bool operator<(const pair<T, U>& x, const pair<T, U>& y);
template<class T, class U>
bool operator>(const pair<T, U>& x, const pair<T, U>& y);
template<class T, class U>
bool operator<=(const pair<T, U>& x, const pair<T, U>& y);
template<class T, class U>
bool operator>=(const pair<T, U>& x, const pair<T, U>& y);
namespace rel_ops {
template<class T>
bool operator!=(const T& x, const T& y);
template<class T>
bool operator<=(const T& x, const T& y);
template<class T>
bool operator>(const T& x, const T& y);
template<class T>
bool operator>=(const T& x, const T& y);
};
};
Include the STL standard header <utility> to define several templates of general use throughout the Standard Template Library.

Four template operators -- operator!=, operator<=, operator>, and operator>= -- define a total ordering on pairs of operands of the same type, given definitions of operator== and operator<.

If an implementation supports namespaces, these template operators are defined in the rel_ops namespace, nested within the std namespace. If you wish to use these template operators, write the declaration:

using namespace std::rel_ops;

which promotes the template operators into the current namespace.

#4
华龙2007-05-01 20:10
以下是引用yuyunliuhen在2007-4-30 23:55:51的发言:

你的意思是?
一般情况就不说了,今天查MSDN的时候也看到这个情况
// expre_reinterpret_cast_Operator.cpp
// compile with: /EHsc
#include <iostream>

// Returns a hash code based on an address
unsigned short Hash( void *p ) {
unsigned int val = reinterpret_cast<unsigned int>( p );
return ( unsigned short )( val ^ (val >> 16));
}

using namespace std;
int main() {
int a[20];
for ( int i = 0; i < 20; i++ )
cout << Hash( a + i ) << endl;
}

也就是说我们自己定义的命名空间都保存在一定的文件当中,而标准命名空间保存在哪个文件当中?

#5
yuyunliuhen2007-05-01 21:37

在VC下的include文件夹下吧,
就版本不是用#include<iostream.h>么,新版本应该还旧版本兼容的,iostream.h,iostream。。。都在那个文件夹下

#6
weishj2007-05-01 22:15
namespace std定义在utility.h中呀
#7
华龙2007-05-02 13:25
以下是引用weishj在2007-5-1 22:15:03的发言:
namespace std定义在utility.h中呀

我打开看怎么没有啊?

1