代码之家  ›  专栏  ›  技术社区  ›  Vallisha

cin的数据类型是什么

  •  3
  • Vallisha  · 技术社区  · 6 年前

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

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

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

    到底是什么?

    2 回复  |  直到 6 年前
        1
  •  5
  •   sorush-r    6 年前

    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 implementation on 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
    
        2
  •  4
  •   Java Rookie    6 年前

    cin 是一个 对象 istream