我试图开始使用命名空间的正确(或至少最好)的方式。命名空间的用法
我试图做的第一件事是避免将using namespace xxx;
放在我的文件的开头。相反,我想using xxx::yyy
作为尽可能本地。
下面是说明这是一个小程序:
#include <iostream>
#include <cstdlib>
#include <ctime>
int main() {
using std::cout;
using std::endl;
srand(time(0));
for(int i=0; i<10;++i)
cout << rand() % 100 << endl;
return 0;
}
如果我省略了线using std::cout;
或using std::endl
,编译器会时,我尝试使用cout
或endl
抱怨。
但为什么这不需要srand
,rand
和time
?我很确定他们在std
,因为如果我试图在他们面前特别倒入std::
,我的代码工作正常。
\ *咳嗽\ * misfeature \ *咳嗽\ * – GManNickG 2010-01-22 09:39:43