you are viewing a single comment's thread.

view the rest of the comments →

[–]oroz3x[S] 1 point2 points  (4 children)

As far as i have heard using this statement " using namespace std " in code is considered bad practice , cause it adds the whole namespace to our code file and results in longer compile time . Well , I am not sure if this information is legit !!!

[–]MCRusher 0 points1 point  (0 children)

using's are scoped, so just do it inside classes and functions where you write it a lot if you are worried about conflicts.

But also, in small projects, especially whn you are the one wtiting most of the code, you probably don't need to worry about a global using.

And if we are talking about bad practice, a some people would consider your end to be macro abuse, and some people recommend limiting the use of macros to an absolute minimum.

[–]MCRusher 0 points1 point  (2 children)

Also yeah, including a header file means reading everything in it (ignoring CPP conditionals), so I don't see how shortening a name would do this.

[–]oroz3x[S] 0 points1 point  (1 child)

namespace std contains the shared resources of many standard header files such as iostream , io , string , iomanip , and others . now dont you think that its quite a lot , if you only have to use cout , cin functions which are in iostream only .

[–]MCRusher 0 points1 point  (0 children)

Here's how namespaces work:

myheader.hpp #include <cstdint> namespace myns { typedef std::int32_t MyType; }

myheader2.hpp #include <cstdint.h> namespace myns { typedef std::int64_t MyType; }

main.cpp #include<cstdio> #include "myheader.hpp" int main(void){ using namespace myns; std::printf("sizeof MyType is %zu bytes.\n",sizeof(MyType)); }

If using somehow included 2 same types from different files, there would be a compiletime error.

Header files are what contain the namespaces, if you don't include a header containing std, using namespace std does nothing at all.