I use Turbo c to compile my c++ programme but it does not consider using namespace std as a keyword |
Update your compiler. Borland Turbo C++ is
ancient. Like... pre-standard ancient. It's a dinosaur. It's not even really C++.
What is the use of "using namespace std" in c++ programme. |
cout, string, etc -- all the identifiers you are used to using are inside of the "std" namespace. Having them in a separate namespace prevents name conflicts.
IE: if you create your own class named string, it would conflict with the standard class with the same name, which might lead to linker errors.
So, having them in a separate namespace prevents those conflicts. The class is no longer just named "string". Now it is "std::string"
1 2 3 4 5 6 7 8
|
#include <string>
int main()
{
string foo; // <- error, what is 'string'? There is no 'string'!
std::string bar; // <- OK. You mean the 'string' that is inside the std namespace. Gotcha
}
|
The line
using namespace std;
takes the
entire std namespace (cout, string, vector, map, etc, etc, etc) and dumps them all into the global namespace... effectively removing the namespace entirely. This allows you to shortcut typing the names, but also means you have the possibility for name conflicts (since they're no longer in a separate namespace:
1 2 3 4 5 6 7 8 9
|
#include <string>
using namespace std; // <- take everything in the std namespace (like std::string)
// and bring it into the global namespace
int main()
{
string foo; // <- OK. Because 'string' is now recognizable since we dumped std::string
// into global namespace
}
|
after using this keyword I tried std::cout<<"\n"; but there is some syntax error. |
Again... this is because your compiler is so old that it is not really compiling C++. It's compiling some unstandardized language that is kind of similar to C++.... but isn't actually C++.
Update your compiler.