什么是cin的数据类型

What is datatype of cin

本文关键字:数据类型 cin 什么      更新时间:2023-10-16

我想知道cin到底是什么。我的意思是函数或类。

我确信它不是一个函数,因为我们使用 cin 的方式与调用的函数非常不同。

这留下了类或对象或其他选项。

到底是什么?

C++ 标准§27.4.1 [iostream.objects.overview]

#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 标头声明将对象与 中声明的函数提供的标准 C 流 (27.9.2(,并包括使用这些标头所需的所有标头 对象。

你也可以看看gcc在github上的实现:

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
  // Standard stream objects.
  // NB: Iff <iostream> is included, these definitions become wonky.
  typedef char fake_istream[sizeof(istream)]
  __attribute__ ((aligned(__alignof__(istream))));
  typedef char fake_ostream[sizeof(ostream)]
  __attribute__ ((aligned(__alignof__(ostream))));
  fake_istream cin;
  fake_ostream cout;
  fake_ostream cerr;
  fake_ostream clog;
#ifdef _GLIBCXX_USE_WCHAR_T
  typedef char fake_wistream[sizeof(wistream)]
  __attribute__ ((aligned(__alignof__(wistream))));
  typedef char fake_wostream[sizeof(wostream)]
  __attribute__ ((aligned(__alignof__(wostream))));
  fake_wistream wcin;
  fake_wostream wcout;
  fake_wostream wcerr;
  fake_wostream wclog;
#endif
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace

cinistream 类的对象