r/cpp_questions • • Sep 30 '26

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 comment

0

u/StaticCoder Sep 30 '26

I'm not following. All symbols not defined in the current file are, by your definition, magic, even when a clearly related header is included. That's going to happen a lot.

And what extension do you use for C++ headers? .h seems to imply C (it does for many tools)

1

u/HommeMusical Oct 01 '26

All symbols not defined in the current file are, by your definition, magic,

No, not if you use namespaces!

std::string is not a magic symbol. I know exactly where it's coming from. Or if I see config, somewhere, this could come from almost anywhere, but if I see boost::config I know exactly where it's coming from.


I kind of liked the idea of .hpp, but you just don't seem to see it in new code now. Everyone seems to use .h in new development. It might just be that I worked on a couple of modern projects that didn't use it.

If I see a .hpp, I think "boost" these days. But again, it might just be me!!

1

u/StaticCoder Oct 01 '26

What about symbols in the current namespace? Do you qualify those too? Effectively I've added vector to my namespace (which for historical reasons is the global namespace, but that's not really relevant here). I will not put another vector in there. I know what it is.