c++ STL cout source code

六月ゝ 毕业季﹏ 提交于 2019-12-07 21:40:25

问题


I want to see source code of STL std::cout function. I looked at iostream, but I've seen only "extern cout". So, I guess that it's defined somewhere in the library.

I downloaded source code from official site

I extracted it and did:

sh@sh-R528-R728:~/desktop/stl$ grep -F * | grep "cout"

but I got nothing.

What am I doing wrong? Where is the source code?


回答1:


cout is not part of the STL, so you won't find the source for cout in the STL source.

You probably want to look for the source for your C++ standard library, which was based on the STL, but also contains iostreams. Where that is depends on what platform you're using.




回答2:


If you happen to be using GCC, then libstdc++ is your C++ library. Its sources can be found on gcc.gnu.org. cout is defined on line 58 of src/c++98/globals_io.cc.




回答3:


std::cout is not a function, it is a instance of std::ostream (interface description) that is tied to standard output.

If you are using gcc/libstdc++, have a blast browsing its source code online



来源:https://stackoverflow.com/questions/10676336/c-stl-cout-source-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!