+ 1
What does "using namespace std" do? What do they really mean by standard namespace
2 ответов
+ 5
If you wanted to do cout, you could do two things:
1.
using namespace std;
cout << "Hello, world!" << endl;
2.
std::cout << "Hello, world!" << endl;
// And for everything accessing the
// standard library, you'd have to
// prefix it with std::.
So, ann in all, it's just to save you time.
+ 1
First of all, std is a C++ Library. So, by using namespace STD, you're connecting your code to that library. This allows the compiler to know what you're referring to when you use cout or cin.
However, you don't necessarily need to use namespace std. Be mindful, though, that this will prevent your program from automatically connecting to the library. You'll have to fetch each individual statement from the library like so: std::cout << "hi"
It's standard, because, well, it consists of the statements that are used pretty often for output and input. It also saves you some time so you don't have to type std::[statement] frequently.