Why is it mandatory to use namespace std
in new compilers whereas the programs written in Turbo C++/Borland C++ don't require namespace std ?
This works in old compilers
#include <iostream.h>
int main () {
cout << "Hello Programmers";
return 0;
}
but we have to write the below given program in new compilers instead of the above one, as the above programs don't work in new compilers.
#include <iostream>
using namespace std;
int main () {
cout << "Hello Programmers";
return 0;
}
That's because turbo-c++ was released even before any c++ standard was released, and they didn't introduce a std
namespace.
It was never updated since then.
Also it isn't mandatory to use the using namespace std;
statement, but rather discouraged.
The code should be:
#include <iostream>
int main () {
std::cout << "Hello Programmers";
}
or
#include <iostream>
int main () {
using std::cout;
cout << "Hello Programmers";
}
Also IMO questions about turbo-c++ are quite futile this time. It's outdated and not remotely has to do anything with modern c++.
If your professors / teachers force you to use it1, tell them that they're doing it wrong and don't teach c++ in any way.
1)I know it's common at indian schools, but that's simply bad practice, and doesn't have a sound reasoning.
May be they want you to teach some things from scratch, because turbo-c++ doesn't support containers like std::vector
or such.
But I still believe that's the wrong approach, because manual memory management is advanced stuff, and shouldn't be used to confuse beginners.