我想了解它是如何工作的...
在 <iostream>
头文件中,存在 namespace std
:
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
namespace std {
extern istream cin;
extern ostream cout;
extern ostream cerr;
extern ostream clog;
extern wistream wcin;
extern wostream wcout;
extern wostream wcerr;
extern wostream wclog;
}
因此,cout
是类型为ostream
的对象的名称,并且由于extern
的原因,在另一个文件中定义。好的。
当我在我的简单程序中尝试创建ostream
对象时,我无法这样做,因为ostream
类的构造函数是protected
的。好的。
那么,我该如何创建(定义)一个在外部文件中具有protected
构造函数且看起来像全局变量的对象呢?