what is the use of "using namespace std;"

Feb 11, 2010 at 6:44pm
what..is..it..it..is.not..working..with..programs
Feb 11, 2010 at 6:48pm
it stops you from having to type std:: before everything for example

std::cout << "Hello World";
becomes
cout << "Hello World";

I do also believe you cxan use it for other things like in Visual C++ when you generate a form it does some

using namespace system; or something similar

Hope it helped.
Feb 11, 2010 at 7:28pm
Feb 11, 2010 at 11:10pm
we can also use

# include <conio.h>


for the same purpose right??




@tummychoww i am using Turbo C++ that is why i have to include the library file too
Last edited on Feb 12, 2010 at 9:15am
Feb 11, 2010 at 11:14pm
Ew. conio is nonstandard. It should generally be avoided. And how can you replace using with the inclusion of another library?
Feb 11, 2010 at 11:22pm
using namespace std; Introduces every name from the std namespace into the current scope block.

It saves you from having to fully qualify names as Timbo described in his example.

I do also believe you cxan use it for other things like in Visual C++ when you generate a form it does some

using namespace system; or something similar

I believe you are thinking of one of the .NET managed languages, such as C# or C++/CLI. There is no "system" namespace in the standard C++ libraries.

we can also use

# include <conio.h>

for the same purpose right??

No, including a header file has nothing to do with namespaces and name resolution.

See here:
http://www.cplusplus.com/doc/tutorial/namespaces/
Last edited on Feb 11, 2010 at 11:23pm
Feb 11, 2010 at 11:31pm
closed account (z05DSL3A)
about namespace using declarations
http://www.cplusplus.com/forum/beginner/9181/#msg42419
Feb 11, 2010 at 11:49pm
let´s ask the Op a question first: Do You know what namespaces are for?... the understanding of this topic may solve the questions...
Feb 12, 2010 at 6:28am
another example,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

namespace first
{
     double var = 5;
}

namespace second 
{
     double var = 10;
}

int main () {
std::cout << "5 plus 10 equals " << first::var + second::var << std::endl ;
std::cin.get();
return 0;
} 


Notice how since you declared namespaces you can use the same variable as long as you put the proper namespace decoration in front of it.

Some one tell me if this is a good example or if it works at all *sigh*
Last edited on Feb 12, 2010 at 6:28am
Topic archived. No new replies allowed.