1.If cin and cout objects are in the 'iostream' , why do we need to declare it again using 'std' ?

2.are cout,cin,cerr,clog the only ones in the iostream?

3.under which categories do cin,cout and iostream fall? (library,object etc..)

4.can we use the same iostream for both linux and windows? how come?

  1. and where can I find the real code of iostream?

  1. because it's in the std namespace, as are all the other classes in the fstream and iostream header files.

  2. dont' know, but Mike probably does

  3. Yes, because they are implemented by different compilers. The same iostream is implemnentsed by all c++ compilers, that doesn't mean they are all implemented in the same way. All the underlying code is operating-system dependent. We as programmers just don't see it.

where can I find the real code of iostream

If you have a c++ compiler then you already have it, or most of it. Just read the header files, but be warned that the header files are nearly undreadable. Some of the source code is in libraries or DLLs or shared libraries, depending on the compiler. To see that you will have to spend a lot of $$$ to buy it from the compiler vendors, except for open source compilers such as gnu. In that event, just download all the gnu compiler's source code and read to your heart's desire.

All the underlying code is operating-system dependent

what do you mean? does the same 'iostream' file have codes for both windows and linux? or do different implementations use different flavors?

3.under which categories do cin,cout and iostream fall? (library,object etc..)

you kind of missed this question

1.If cin and cout objects are in the 'iostream' , why do we need to declare it again using 'std' ?

<iostream> is the header that contains declarations. Without those declarations your compiler doesn't know that the names you use exist. The names themselves are declared within a namespace to avoid collision with other libraries.

Headers and namespaces are not used for the same purpose. In this case you're "declaring" namespace std to save you the trouble of constantly using the fully qualified name each time. Otherwise you'd end up typing std::cout instead of just cout.

2.are cout,cin,cerr,clog the only ones in the iostream?

Yes (including wide counterparts). But keep in mind that there's a metric shit ton of scaffolding behind those objects, which you'll find in headers such as <ios>, <istream>, and <ostream>. <iostream> is conceptually just the header that defines the objects cout, cin, cerr, and clog. But those objects have types which are defined in other headers.

The <iostream> header can be as little as this:

#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>

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;
}

3.under which categories do cin,cout and iostream fall? (library,object etc..)

cin and cout are objects in the standard I/O library.

4.can we use the same iostream for both linux and windows? how come?

<iostream> is a standard header with well defined rules that every compiler must follow. So yes, you can confortably use it regardless of the host system and expect the same behavior. Sometimes there are bugs, and there are a number of corner cases where the implementation can make a different decision, but in general the same functionality is required.

and where can I find the real code of iostream?

See the headers I included in the above example of <iostream>? Dig down into your compiler's includes folder and find them. You may need to open more headers based on how those are defined, but that's your starting point.

does the same 'iostream' file have codes for both windows and linux?

To us programmers they are all the same code, the operating system is transparent to the programmer. For example your program uses cout the same way on all operating systems, and that's because there is an international c++ standard. The c++ standards committee dictates to all compiler vendors what functions/classes have to be implemented, but do not say how the functions/classes are to be implemented. You can write cout << "Hello World\n the same way with all c++ compliant compilers. We are not normally concerned about how compiler makers implement standard c++ functions/classes , unless of course you write your own compiler or work for a company that make compilers.

you kind of missed this question
Yes, that was my answer to #4, not #3.

<iostream> is a standard header with well defined rules that every compiler must follow. So yes

Is actualy code different for each OS but the functionalty is the same?

Is actualy code different for each OS but the functionalty is the same?

The code is different for each compiler, even compilers on the same OS. But the functionality is defined by a standard rules document that all compilers must adhere to.

found 'em thanks! hey I thought Visual studio 2010 compiler is not open source therefore I won't be able to find thoses files there

See the headers I included in the above example of <iostream>? Dig down into your compiler's includes folder and find them. You may need to open more headers based on how those are defined,

Isn't 'iostream' a part of the c++ library? why do some people call the <iostream> a library, not a file of the standard libarary?

the declarations are in header files so all compilers will provide them just like they provide all other header files.

I thought Visual studio 2010 compiler is not open source therefore I won't be able to find thoses files there

These are template classes. Without getting too much into it, due to the way templates are implemented, it's drastically more efficient to keep all of the code together rather than separating declarations and definitions. So template classes are nearly always implemented fully in the header file. Provided the header is actually stored as a viewable file, you can look at the code.

Isn't 'iostream' a part of the c++ library? why do some people call the <iostream> a library, not a file of the standard libarary?

Because everyone knows what you mean when you say the iostream library, there's no ambiguity. Why waste time with a pedantic description when there's no need? There may also be a historical reason, where there were originally many different libraries (of which iostream was one), and they were basically collected into the current "standard" library.