Noob question about library source code

Consider the following:

1
2
3
4
5
6
7
#include "stdafx.h"
#include <iostream>

int main()
{
	std::cout << "I am a noob.\n";
}


The "std::cout" part points to a library function, right?
I would like to view that actual source code of that function that actually puts the text on the screen for me (via the compiler). Is that possible? I'm using Visual Studio Community 2015.

So am i right in thinking that when one uses a library function, that is actually just a bit of c++ source code that's been written for you (hopefully by a C++ expert!), and is kept hidden from view (in the Visual Studio text editor) simply because it works and doesn't normally need to be seen? But actually one could, if one wanted to, view the entire source code of a solution?

So what i'm basically asking is, is there something fundamentally different from the code i write and the code (which is kept from view) that makes up library functions?
Last edited on
The "std::cout" part points to a library function, right?
No, it points to library object.

It is used by function operator<< (std::ostream&, const char*) which is implemented inside library too.

For VS Community Edition, Microsoft standard library implementation is inside VS install path in /crt/src directory.

So am i right in thinking that when one uses a library function, that is actually just a bit of c++ source code that's been written for you (hopefully by a C++ expert!), and is kept hidden from view
Yes. For non-source libraries you can use any language, not only C++, and use that library in C++.
But actually one could, if one wanted to, view the entire source code of a solution?
If library discloses its source, sure.
is there something fundamentally different from the code i write and the code (which is kept from view) that makes up library functions?
Often that code is platform dependend (for example if you would take code from MS library implementaion regarding console output and compile it on Linux it will not work) or uses non-standard language extentions: standard library is implementation detail and is not required to adhere to language standards (and some parts of standard library is impossible to implement in raw language without compiler support)
Thanks for the reply / info!

You said:
For non-source libraries you can use any language, not only C++, and use that library in C++.

I don't quite follow that. What do you mean by "non-source library"? And you're saying you could use code from another language (like Python) in your c++ solution, if it's packaged into library? How does that work?

What i'm still not understanding is: does that source code for (for example) std::cout get inserted by VS2015 (behind the scenes, while i'm writing the program), or by the compiler at compile time? I would imagine the compiler would say: "puleeeese, i know what std::cout means, you don't need to spell it out every time!"
Last edited on
What do you mean by "non-source library"?
There are libraries where you have sources and can just add them to your project, like any other header/implementation file and compile them yourself.
And there are libraries which provide you a header, which acts like an interface providing declarations of entities you may use and prebuilt binary (either a dynamic - dll - library, which you must load in runtime, or static, which you must link to program). As it is built already, it is in machine code already, not C, C++, Delphi, etc.
In practice C function interface used as almost all languages support it directly or indirectly. There exist some libraries which exposes C++ style classes for use only with C++.


And you're saying you could use code from another language (like Python) in your c++ solution, if it's packaged into library?
Pyton is not a compiled language, so you cannot make a binary out of it directly. However you can interact with Pyton code by use of some medium.

does that source code for (for example) std::cout get inserted by VS2015 (behind the scenes, while i'm writing the program), or by the compiler at compile time?
Implementation code for standard library entities resides in C++ runtime library. It might be linked to your program statically (like any other cpp file, but it is compiled already for you, only linking stage remain) or dynamically (Ever saw errors like "VCredist XXXX needed"? This is a C++ runtime library where cout implementation code resides).

Including required parts of runtime library is a compiler magic. You are not supposed to worry how it works and interfere with it (sometimes you are allowed to make small changes like choosing dynamic or static linking)
Topic archived. No new replies allowed.