+ 1
What is the problem with using namespace std.
my question is: what problem will occur with [using namespace std] instead of [std::(something)] and if we use cout in our program if we use: [using std::cout] have any difference with using [std::cout] on all the lines?
2 Answers
+ 6
using namespace std; is just a clever way to get things done. When you use this command, the compiler assumes that all the functions that you have used in your code, if are present in the std namespace, must be referring to the functions from the namespace itself. Thus, if you use using namespace std, and perform this:
cout<<max(2,4);
The compiler assumes the max function to be the std::max function of C++, and even if you try to define a max function with a different syntax or algorithm (like max is made to return min), the compiler still calls std::max, when you did not want this to happen, or will return errors.
And even when you have included 'using namespace std; ' in your program, you can still call something like this:
std::cout<<std::max(2,3)<<std::endl;
Since using namespace std raises an ambiguity in some cases, it is considered bad to use it.
https://www.sololearn.com/discuss/294730/?ref=app