+ 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
5 Antworten
+ 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?
+ 6
"std" is a namespace, not a class.
https://en.cppreference.com/w/cpp/language/namespace
+ 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
+ 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