cross-posted from: https://lemmy.ml/post/70930

I am learning C++ and in my book using namespace std is written in every program. I understand that std::cout <<"hello"; can be simply written as cout << "hello"; by using namespace std.

Why?

  • Multivortex Tornado@feddit.de
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 year ago

    Correct. While using the namespace saves some time when writing (and some space when printing), it may lead to excess time used debugging later when a name clash happens.

    The last point might not be a concern for small “toy programs” used for educational purposes. It is still bad style and should be avoided, especially for toy programs used for educational purposes, though.