I just started C++ and started doing basic text to console programs. In the book that I'm reading (Which is pretty old, I think) it uses cout to write stuff to the screen. Simple enough, right? But when I try to write cout it says that it's not defined. I searched around the internet and it said that I need std::cout or using namespace std; How does this stuff work? Explain it to me like you would to a 5 year old. I'm next level stupid.
Asked
Active
Viewed 61 times
-4
-
2Your book should explain this. If it doesn't, get a better book. *The C++ Programming Language* by *Bjarne Stroustrup* will suffice. – DeiDei Oct 29 '16 at 17:51
-
1The name of the standard output stream is `std::cout`. Don't do `using namespace std;`. – Pete Becker Oct 29 '16 at 17:55
-
List of recommended reading: https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – Galik Oct 29 '16 at 17:58
-
(`I'm next level stupid` (Don't _call_ it stupid - use _dense_.) Let me introduce you to [rubber ducking](https://en.wikipedia.org/wiki/Rubber_ducking).) – greybeard Oct 29 '16 at 18:51
1 Answers
0
std
is the namespace which contains all functions and classes of the standard library. namespaces are used to avoid clashes of functions/classes with the same name. You can define a namespace northern_guy
which contains a class cout
.
std::cout << "output"; //prints to standard output
northern_guy:cout << "output"; //does what ever is defined in that namespace
(For this example you need to overload the << operator)
So you can use both functions/classes alongside in your code. That's why you should not use using namespace std;

e-dschungel
- 88
- 4