【发布时间】:2023-10-13 16:14:02
【问题描述】:
我的计算机科学教授希望我们找到cout 的声明。我使用 g++ 和 -E 参数编译了一个简单的 Hello world 程序。这是我的 hello.cpp 的样子:
#include <iostream>
using namespace std;
int main(){
string name="";
cout << "Good morning! What's your name?";
cin >> name;
cout << "Hello " << name << ".\n";
return 0;
}
我的编译命令:
g++ -E hello.cpp > hello.p
在 hello.p 中,我在 VIM 中进行了搜索,如下所示:
:/cout
我看到以下行:
extern ostream cout;
这是cout 的声明,cout 是ostream 类的实例吗?
编辑:
wcout 声明有什么用?如果我没记错的话,字母“w”代表“宽”,但我不知道它有什么含义。 wcout 和 wostream 是什么?
【问题讨论】:
-
我愿意猜测当您链接到 IOStream 时附加到可执行文件的代码中的某个位置。
-
@Aslai - 我已经从该代码中提取了一行。我想知道是不是这样。
-
试试这个:cplusplus.com - 在搜索框中输入
cout。 -
是的,cout 是 ostream 类的一个实例。
标签: c++ terminology cout ostream