+ 12

About std in C++

Is std a class of the file <iostream>? (i know iostream is a header file) or is it a separate .h header file ? ,the latter seems incorrect

8th Sep 2018, 9:00 PM
FIREmonger
FIREmonger - avatar
5 Respostas
+ 13
Hatsy Rei thanks for the "label container" explanation...i got it & thanks James for promt of finding out the stl file!
8th Sep 2018, 10:50 PM
FIREmonger
FIREmonger - avatar
+ 10
Hatsy Rei encapsulation hurts my brain, std sounds like a class but it is not it is name space...just read the first sentences of your link is namespace a class?
8th Sep 2018, 10:02 PM
FIREmonger
FIREmonger - avatar
+ 6
"std" is a namespace, not a class. https://en.cppreference.com/w/cpp/language/namespace
8th Sep 2018, 9:43 PM
Hatsy Rei
Hatsy Rei - avatar
+ 5
ICEmonger Not exactly, if not at all. A class is a blueprint for object creation. A namespace is more akin to a labelled container. Imagine if both you and I have laptops of the same model, and they look exactly the same. Namespaces would be this bag with our name on it. Placing our laptops in our respective bags will prevent confusion as to which belongs to whom. namespace james { std::string laptop = "James' data"; } namespace rei { std::string laptop = "Rei's data"; } We can then invoke our laptops separately. std::cout << rei::laptop; This is an example I made a while ago: https://code.sololearn.com/ca0X1CRI8ZoS/?ref=app
8th Sep 2018, 10:10 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
std is a namespace, eg: namespace std{ class basic_iostream{ }; typedef basic_iostream iostream; iostream cout; } to access your class you need to follow the scope order: eg let's access cout object : std::cout<<"hi\n"; please note this is Just an example I'm not saying that's how the namespace is implemented
9th Sep 2018, 6:34 AM
Germain F
Germain F - avatar