For every new code, is it necessary to identify a header #include <iostream>, as well the name space? I thought one should do? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

For every new code, is it necessary to identify a header #include <iostream>, as well the name space? I thought one should do?

#include <iostream> using namespace std;

28th May 2017, 12:45 AM
Martial Arts
3 Answers
+ 8
Still trying to get used to not doing 'using namespace std'. For each time I forget to do std:: without it and the compiler throw errors, it feels like coming back from school and suddenly your mom doesn't recognise you lol.
28th May 2017, 1:52 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
No, neither are neccessary. #include <iostream> is just adding the iostream functions to your program so you can use them, such as cin and cout. Try to take away the #include. No, you will not have any problems. Now try to write cout << "lel"; Uh oh, what is cout? Never heard of it, says the compiler. Now put back the iostream header. What happens if I dont say namespace std? Well, now I have to write: std::cout << "lel"; If i want to use cout. As it is in the standard namespace.
28th May 2017, 1:20 AM
Rrestoring faith
Rrestoring faith - avatar
- 2
yes. needed for everyone
28th May 2017, 12:47 AM
Martial Arts