0
What is using namespace std. I didn't understood it
in my book there is no command like using namespace std
3 odpowiedzi
+ 5
The namespace std stands for the standard namespace. Wow, what does that do?
Basically, it is needed for many different uses, the simplest of which are cout and endl. Let's have an example.
#include <iostream>
using namespace std;
int main(){
cout << "Hello World" << endl;
return 0;
}
//Hello World
So far, so good. Simple, you might say. Now, suppose we eliminate the second line:
#include <iostream>
int main(){
cout << "Hello World" << endl;
return 0;
}
//Error: 'cout' was not declared in this scope
(same for endl, by the way)
As you can see, you need the namespace std to access some important functions. However, if you're using multiple namespaces, it is usually better to do this:
#include <iostream>
int main(){
std::cout << "Hello World" << std::endl;
return 0;
}
//Hello World
Hope this helped. 😉
+ 1
using namespace std let u access to standard library in cpp such string or vector , if u dont , for example to use tge cout , u have to access to it using :: , std::cout , so to make it simple , u use std namespace and just call cout
0
its just a library and you dont need to think about that much if you are a beginner