#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
If I remove the 2nd statement,the build will fail.
Why is it necessary?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because
coutandendlare contained inside thestdnamespace.You could remove the
using namespace stdline and put insteadstd::coutandstd::endl.Here is an example that should make namespaces clear:
Stuff.h:
When you do something like
using namespace Hardwareyou can use Nut without specifying the namespace explicitly. For any source that uses either of these classes, they need to 1) Include the header and 2) specify the namespace of the class or put a using directive.The point of namespaces are for grouping and also to avoid namespace collisions.
Edit for your question about why you need #include :
#include <iostream>includes the source forcoutandendl. That source is inside the namespace called std which is inside iostream.