cout is declared in iostream, but where it is defined?

后端 未结 1 547
-上瘾入骨i
-上瘾入骨i 2021-01-21 12:05

When I try to see definition of cout, I land to iostream file where it is declared as,

extern _CRTDATA2 ostream cout;

So where it is defined? B

相关标签:
1条回答
  • 2021-01-21 12:59

    Global symbols are defined in a run-time library that you link with your applications. For example, in gcc you pass the compiler option -lstdc++ that will link your application with the libstdc++.a library. That is where all such symbols reside.

    Though, this is specific to your compiler/run-time library version and will vary. Microsoft Visual C++ may behave differently but the idea is the same: the symbols are inside the precompiled libraries that are delivered with your C++ compiler.

    With GNU you can type:

    nm -g libstdc++.a
    

    to see the symbols inside the library. The output may look like this (among lots of other lines):

    ios_init.o:
                     U _ZSt3cin
    globals_io.o:
    0000000000000000 D _ZSt3cin
    0000000000000000 D _ZSt4cerr
    0000000000000000 D _ZSt4clog
    0000000000000000 D _ZSt4cout
    0000000000000000 D _ZSt4wcin
    0000000000000000 D _ZSt5wcerr
    0000000000000000 D _ZSt5wclog
    0000000000000000 D _ZSt5wcout
    
    0 讨论(0)
提交回复
热议问题