应该包含哪些标题,以便在Linux上的c ++代码中保留前缀std ::?

Rol*_*oka -4 c++ header header-files

我想在Linux操作系统上使用我的c ++代码中没有std ::的语句(例如cout而不是std :: cout,map <>而不是std :: map <>等).执行它需要什么标题?

Tas*_*Tas 7

正如评论者所指出的那样:没有包含这样做,你只需像往常一样包含你的文件,然后写一个using namespace声明

#include <iostream> // cout
#include <map> // map

using namespace std; // bring this entire namespace into scope
Run Code Online (Sandbox Code Playgroud)

然而 ; 您应该注意,并且评论者指出,这是一个可怕的想法, 尤其是在头文件中.对于您需要编写的额外几个字符,您可以在以后节省数小时的麻烦.如果您真的反对写作std::,请考虑限制您执行此操作的范围

{
    // lots of console printing:
    using std::cout;
    cout << "";
    ...
}
// Now you'd need to write std::cout again
Run Code Online (Sandbox Code Playgroud)

这与操作系统无关(Linux的解决方案与其他操作系统相同)


归档时间:

查看次数:

141 次

最近记录:

8 年,10 月 前