You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
some other codes/other websites, I found they don't use "std::". instead, some of them said that "using namespace std" after header filer is replacing this "std::".
is this a good practice to use the "std::" every time?
The text was updated successfully, but these errors were encountered:
@mdsiaofficial
It's about good practice, for a simple project like this where the purpose is to just experiment its fine to use "using namespace ". But for larger projects usage of this is not recommended, as it may get confusing if the included headers files also have them.
// main.cpp
#include"temp.cpp"voidcout()
{
// to confuse
}
intmain()
{
std::cout << "doing something" << std::endl; // will work fine as we explicitly mention the namepsace "std"
cout << "will get confused now" << endl; // compile error will get confusedcout(); // compile error will get confusedsomething();
return0;
}
Although you can avoid this by putting temp.cpp code into a namespace temp and in main cpp create a "using namepace " for it, but then the cycle may repeat for someone trying to include main.cpp
some other codes/other websites, I found they don't use "std::". instead, some of them said that "using namespace std" after header filer is replacing this "std::".
is this a good practice to use the "std::" every time?
The text was updated successfully, but these errors were encountered: