c++ - cout在哪里声明?

标签 c++ terminology cout ostream

我的计算机科学教授要我们找到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的声明,coutostream类的一个实例吗?

编辑:

那里的wcout 声明是做什么用的?如果我没记错的话,字母“w”代表“宽”,但我不知道它有什么含义。什么是 wcoutwostream

最佳答案

是的,这确实是std::cout的声明, 在 <iostream> 中找到标题。

相关标准件参见§27.4.1 [iostream.objects.overview] :

Header <iostream> synopsis

#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;
}

p1 The header <iostream> declares objects that associate objects with the standard C streams provided for by the functions declared in <cstdio> (27.9.2), and includes all the headers necessary to use these objects.

关于c++ - cout在哪里声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9652374/

相关文章:

c++ - 展开和转发阵列

c++ - 您在哪里跟踪新的 c++ 标准的发展?

terminology - 跨浏览器/桌面应用程序的术语?

c++ - cout 不一致地打印字符串和变量值,使输出不对齐

c++ - Cout 给出了一个奇怪的输出

C++ 忽略某些输出的 cout 重定向

c++ - 在 Windows 上用什么替代 glob_t 和 glob()?

C++ 正则表达式字符类不匹配

unicode - 关于字符编码的问题

terminology - "low ceremony"是什么意思?