Cpp Question 😎 | Sololearn: Learn to code for FREE!


Cpp Question 😎

Why do we use the 'std::cout' when can use only cout <<?

4/8/2018 3:48:23 AM

Eric Lecorps

8 Answers

New Answer


This one got some attention in the answers: https://www.sololearn.com/Discuss/1004636/?ref=app


Since the introduction of using namespace std, there have been arguments about whether it is a good or bad thing. I don't like it because it puts tons of symbol names into your global scope. These names are so numerous that it is likely you don't know them all. You could plan on overloading one of the names and forget to declare it. Now you end up sharing the standard one with random side effects.


This is will tell you about std:: and using namespace std; https://www.sololearn.com/Discuss/294730/?ref=app Example code without using namespaces https://code.sololearn.com/cUx55EsTKnaz/?ref=app


You can only use cout by itself if you have added a using statement for the std namespace. Otherwise you'd receive an error.


John Wells I was very recently digging into gcc and found files like these: https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/c_compatibility/stdio.h ...so when I #include <stdio.h> I think I get this file, which is basically ~50 lines that read: using std::keyword; // times 50 ...is this an easy example of the globals issue?


Eric Lecorps are you brother of Jayden Lecorps


That file is meant to be used in C code, where there you automatically get all the names in global scope for the files you include.


hello Eric what programming language are u learning