Quote:
Originally Posted by Jeebizz
I thought that (at least according to C++ From the Ground Up (book)), that using namespace std; is a way to guarantee that there won't be any namespace conflicts, and as I said before not only std::cout<< seems weird, but also too long winded.
|
By using "using namespace std" you are putting EVERY symbol in std namespace (which is huge) into global namespace. It a good way to generate namespace conflicts or ambiguities, not to prevent it, so it should be used very wisely. It will be smarter to use just one symbol you need instead of exposing contents of entire namespace.
Quote:
Originally Posted by Jeebizz
What does stripping do anyways?
|
Removes all debug information. unstripped binary can be 5..10 times larger than stripped one.
Quote:
Originally Posted by Sergei Steshenko
At the moment you import something, you get a risk of name conflict.
If you always use std::cout, std::cerr, std::cin, you don't.
|
It's not quite right. "never importing anything from namespace" doesn't make much sense.
It is possible to import only std::cin ("using std::cin;") instead of entire namespace.
Code:
#include <iostream>
using std::cout;
using std::endl;
int main(int argc, char** argv){
cout << "1234" << endl;
return 0;
}
And it is possible to import namespace (or symbol from namespace) only within one function or block which will be wiser move.
Code:
#include <iostream>
int main(int argc, char** argv){
using namespace std;
cout << "1234" << endl;
return 0;
}
Code:
#include <iostream>
int main(int argc, char** argv){
{
using namespace std;
cout << "1234" << endl;//works
}
cout << "1234" << endl;//compiler error
return 0;
}