Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ STL cout source code

Tags:

c++

cout

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?

like image 533
Tebe Avatar asked May 20 '12 19:05

Tebe


People also ask

Can you use cout in C?

cin and cout are streams and do not exist in C. You can use printf() and scanf() in C.

Is cout part of STL?

std::cout is also not part of the STL.

What is cout statement in C?

The cout command is a data stream which is attached to screen output and is used to print to the screen, it is part of the iostream library.

Is C++ STL open source?

Microsoft has open-sourced STL to allow it's users easy access to all the latest developments in C++ by trying out latest changes and improving pull requests by reviewing them.


2 Answers

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.

like image 128
Fred Foo Avatar answered Sep 28 '22 09:09

Fred Foo


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.

like image 45
Alan Stokes Avatar answered Sep 28 '22 09:09

Alan Stokes