cout is defined in std namespace and we also include iostream to use cout...i am confused ,please clarify this.where
1)cout is defined
2)where it is declared.
and if we are including iostream ,then what is the need of STD::COUT
That is, you get the object cout, which is in the std namespace. You can use an object in the std namespace either directly:
std::cout << "Something";
or by stating that you want to use that particular object like this:
cout << "Something";
or that you want to use everything from std namespace (this one is generally a bad idea, and if you do it in a header file someone will be very angry)
using namespace std;
cout << "Something";
The object named cout that is part of the namespace std is declared in iostream (or something included from iostream, or maybe in iostream it's simply declared with extern), and that declaration contains the information that cout is part of the std namesapce.
cout will be defined in one of the files that came with your compiler (for example, in the libstdc++), but exactly where and how is up to whoever wrote it. The standard doesn't enforce where it is defined.
If you don't know what namespaces are then you need to read a good tutorial because namespaces are fundamental to c++ language. Namespaces were invented to keep from getting name conflicts from one file to the next, that was a big problem in C language. For example, file A.h might declare a struct named foo, and file B.h might declare another structure with the same name. If both files are included in the same *.cpp file then there is a name clash. Namespace helps prevent that problem.
All (or most) standard C++ header files are under the namespace called "std". So when you write using namespace std; you are telling the compiler to use everything in that namespace regardess of where it comes from. In small pograms like you might write in school that is not a big problem, but in large professional c++ program it can become a problem. There are a couple alternate ways of coding it, such as using std::cin; or just writing std::cin << "Hello World\n";
cout is defined in <iostream> header file. As a beginner, don't try to read iostream header file -- it's a big mess. Just be aware that cin and cout are declared in iostream. If you want to do file io then use fstream, ifstream and ofstream classes. Trying to follow the header files can ruin your brain.