I have searched this question in Google. I found some related question in stackoverflow.com
and quora.com
but i am still not clear about this two topics. Everyone says that we use #include<iostream>
for input/output operation. Now, we take input using cin
and print output using cout
that means this two should be defined in #include<iostream>
. But without using using namespace std
we still can't take any input nor can print something on console. So, my questions are-
- Where is
cin
andcout
actually declared and defined? Is it in#include<iostream>
or innamespace std
? - If in
#include<iostream>
why should we useusing namespace std
? - If in
namespace std
why should we use#include<iostream
?
After reading some article on the web and watching some videos on YouTube, I'm assuming cout
and cin
is defined in namespace std
and the namespace std
doesn't make any sense alone because it is defined in #include<iostream>
. That's why we need to use them both. (Just my thought let me know if I am right or not.)
The purpose of this question is to be clear about this two facts. If you can help it would be great.