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

标准命名空间问题

c++
  •  3
  • Flash  · 技术社区  · 16 年前

    嗨,

     namespace std
       {
    
         declaration of cout 
    
         declaration of cin 
    
         ..... some other declarations etc....
    
       }
    

    以及他们在istream和ostream中的实际实现????

    或者,是不是反过来。。。???比如。。。。

    namespace std 
       {
         complete definition of cout 
         complete definition of cin  
         .........
    
       } 
    

    他们的签名就放在iostream文件里。。。

    iostream file 
      {
        std :: cout 
        std :: cin 
        .....
    
      }
    

    请提供任何例子或链接,你可能认为会帮助我更好地理解

    4 回复  |  直到 16 年前
        1
  •  4
  •   UncleBens    16 年前

    我知道这些功能, 名称空间。

    basic_ostream 和 basic_istream .

    你宁愿包括头,这样你可以编译你的源代码(编译器需要声明等)。

    iostream

    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;
    }
    
        2
  •  2
  •   Billy ONeal IS4    16 年前

    标准上真的没有说。对于实现者来说,完全可以将其作为一个只包含头的库来执行,但是对于他们来说,更可能的是将声明放在头中,并将实现放在CRT中。

    编辑:但是 cin , cout extern 在某种图书馆里定义的。(见叔叔们的回答)

        3
  •  1
  •   Tomasz Kowalczyk    16 年前

    cin 和 cout 不是简单的变量 cerr 它们是默认情况下为使用iostream的每个应用程序注册的流。你不能在不包含标题的情况下使用它们。

        4
  •  1
  •   James Hopkin    16 年前

    cin cout std iostream 使用它们。

    std::ostream 可能在头上 ostream ,包含在 . 也在标题中 奥斯特拉姆 , std::cout 可以定义为对 标准::ostream