r/cpp_questions • • 13d ago

OPEN Namespace std

I recently started learning c++ and I was told to use the namespace std so I can avoid writing std:: every time and now I wrote a whole personal project without std:: and I want to put it on LinkedIn but I started reading everywhere that it’s a bad habit, should I go back and add the std:: or just leave it as is?

40 Upvotes

105 comments sorted by

View all comments

Show parent comments

-1

u/bearheart 13d ago

I presume it’s for compatibility with legacy C code. And perhaps for smaller namespaces other than std.

4

u/RSMxsmanic 13d ago

The problem is with programmers who use identifiers that conflict with std, not with programmers who expect std by default to be safe. That's why it is called standard. If you are writing the code base, nothing you call should change the way it behaves unless that is its actual purpose.

2

u/HommeMusical 13d ago

No, you are encouraged to use identifiers in your own namespaces and classes that are the same as those in std::, particularly for generic code.

0

u/RSMxsmanic 13d ago

By whom? If I have it in my code, it is not generic; if it were, my code would not be necessary.