+ 3
Should I use namespace std
I just restarted C++ (I almost finished but got really busy then forgot chunks of it) and I realized that it always tells us to use namespace std, instead of putting std:: in front of things like cout or cin. My friend (who is way more advanced than me) said to start practicing using std:: rather than using namespace because it is good practice. I couldn't really understand his explanation, something about library ambiguity I think? Should I stop using namespace std?
3 Respostas
+ 6
using namespace std; is helpful, but there is a problem...
Let's say you are implementing your own vector.
If you use `using namespace std;`, the compiler will start complaining because there is std::vector<>.
* `using namespace` imports the whole namespace.
If you are going to use Boost, you will need to use the prefix for the standard namespace and Boost. Forgetting that could be a huge hassle.
-----
I, personally, prefer to use the prefix form because I know that it is cleaner.
+ 5
For simpler programs with no clash of namespaces, using namespace std; is OK.
+ 2
You can use it. You should understand the theory behind it and use namespaces as needed. Do not do anything just because someone sad so, ask why - that is the way to learn.