Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

why are we use using namespace std in C++??

–2 votes
asked Mar 22 by kunjal kanani (330 points)

2 Answers

+1 vote
answered Mar 22 by Ostafe Ionatan (160 points)

Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries. All identifiers at namespace scope are visible to one another without qualification

I foud this on google :)) I hope you enjoy!

+2 votes
answered Mar 23 by Peter Minarik (22,320 points)

The using keyword has a few meanings.

In this case what it does is that whenever you want to use any type from the std namespace, you do not need to include the namespace name.

Consider the below two example for contrast:

#include <iostream>

int main()
    std::cout << "Hello world!" << std::endl;
    return 0;

#include <iostream>

using namespace std;

int main()
    cout << "Hello world!" << endl;
    return 0;

So why wouldn't you always want to use using namespace ___;?

The reason is that there could be classes that are implemented in multiple namespaces. E.g. You can create a Physics::Cube and a Graphics::Cube. If you use both the Physics and Graphics namespace, the compiler wouldn't know what Cube refers to. So sometimes it's wise to cut back on the extensive use of the using keyword.

commented Mar 23 by kunjal kanani (330 points)
how to create graphics using namspace??
commented Mar 23 by Peter Minarik (22,320 points)
edited Mar 26 by Peter Minarik
If you really want to do graphics, you probably should start off with something like a graphics/game engine, instead of trying to do everything from scratch  using C/C++ (, which is certainly possible, but it is a great deal more effort than using a game engine.)

I'd suggest checking out Unity.
- https://learn.unity.com
- https://learn.unity.com/project/fps-template
Note: the scripting in Unity is usually C#, not C/C++.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.