0
iostream.h
I was wondering though from the C++ I learned from school they use iostream.h. Over here we use iostream only and the term "using namespace std". Can someone tell me about it. How it works??
3 Respostas
+ 2
<iostream.h> is old-style iostream header, and it puts everything in the global namespace.
<iostream> is what you should use instead, and it uses a separate 'std' or standard namespace.
'using namespace std' simply said means that it will take everything from the 'std' namespace and put it in the global, which most of the times is fine.
however, if you have classes or functions that clash with, for example, iostream's ones, you wouldn't use 'using namespace std' but instead prefix iostream's code with 'std::', which means essentially "from namespace 'std'". That will allow you to safely define your own 'cout' for example, while keeping the original untouched.
std::cout << "string";
0
I didn't understand the last part of your answer.
Could you explain it??
0
the point of the standard namespace is to protect programmers from accidentally overriding functions/classes etc. it also means you can use the standard library while defining your own classes/functions/etc with the same names like in standard library.
as an example, you could define your own string class, but the original string class would be protected in the std namespace, unless you explicitly override it.
this implies you do NOT "using namespace std;" since it makes everything in that namespace global.