在我的C++代码中,我不使用声明using namespace std;
或using namespace boost;
。这使我的代码更长,意味着更多的输入。我当时正在考虑开始使用“使用”声明,但我记得有人对此表示反对。推荐的做法是什么? std和boost如此普遍,应该不会有太大的危害吗?
最佳答案
我仅在C++文件中使用using namespace
,而不在 header 中使用。此外,在大多数情况下不需要使用空 namespace 。例如,您可以编写using boost::shared_ptr
或using std::tr1::shared_ptr
以在shared_ptr
实现之间轻松切换。
样本:
#include <iostream>
using std::cout;
int main()
{
cout << "test" << std::endl;
return 0;
}
关于c++ - 我应该在所有地方都使用std::和boost::前缀吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1115633/