I am using namespace std;
That's usually a bad idea, unless it's in a narrow scope to keep the pollution away from the rest of the program.
Then, what's wrong with coding this?
Nothing; it's just more verbose than it needs to be. The name is available both as a qualified std::cin
in any scope, and an unqualified cin
in any scope where the name has been dumped by using
. But I'd suggest not dumping the contents of the standard library into any other scope, to avoid the danger of library names conflicting with names I want to use.
What are the disadvantages of mixing both?
You have both the name pollution that namespaces help avoid, and the less readable qualified names that using
helps avoid; the disadvantages of both and the advantages of neither.
Also, how can I replace the code above?
As you say, cin.ignore(numeric_limits::max(), '\n');
will work if the contents of std
have been dumped into an accessible scope. But I'd still recommend getting rid of the using
.