answersLogoWhite

0

A namespace is similar to a class in object oriented programming. A namespace contains functions defined by the programmer. for example namespace std contains functions like cout and cin.

namespaces can be globaly declared like so: "using namespace std;"
which includes all the functions located in the namespace std.
if you only need to use cout you can globaly declare only cout like this "using std::cout;"

or

std::cout<<"calling cout directly from namespace std";

you can make your own namespaces as well

namespace mynamespace;
void myfunction(){
code for function
}

and use it

using mynamespace::myfunction;


The main use of a namespace is to reduce or eliminate collisions with names that may be duplicated but have different functionality. For example, I may want to use an object with the name of 'cout', but that name already exists. If I place it in a different namespace I would be able to use it with that name.

User Avatar

Wiki User

8y ago

What else can I help you with?

Related Questions

Fundamental components of a c plus plus program?

#include &lt;iostream&gt; using standard namespace std; int main() { cout &lt;&lt; "your prob shouldn't be taking c++"; return 0; }


Initialization of variables in namespace in C plus plus?

Is an important thing to do.


Give an example of C plus plus program?

#include&lt;iostream&gt; int main() { using namespace std; cout&lt;&lt;"Hello world!"&lt;&lt;endl; return(0); }


In your program what if you do not provide the following directive in your code using namespacestd hint what will you need to do?

If you do not include the directive using namespace stdin your program, any references to objects in namespace std will need be be qualified with that namespace. For instance...cout


How do you solve this error under-fined symbol 'cin'in c plus plus?

#include &lt;iostream&gt; using namespace std;


Can you program games with c plus plus?

Yes, you can program games with C++.


What are some disadvantages of using namespace in C?

Here's one: there's no namespace in C


What is the program to create a string class which stores a string value in c plus plus?

C++ already provides a string class in the C++ standard template library. #include&lt;iostream&gt; #include&lt;string&gt; int main() { using namespace std; string s {"Hello world!"}; cout &lt;&lt; s &lt;&lt; endl; }


What is global object in c plus plus?

A global object is any object instantiated in the global namespace. The global namespace is anonymous, so if we don't explicitly specify a namespace prior to instantiating an object, that object will be instantiated in the global namespace: int x; // global namespace n { int x; // non-global }; To refer to the non-global, we must use namespace resolution: x = 42; // assign to the global n::x = 42; // assign to the non-global


In c plus plus Programming can you replace STDio header with using name space STD?

No. You can't use namespace std even if you include stdio.h. At the very least you must include stddef.h before you can use namespace std.


Program to find odd number up to range in c plus plus?

#include &lt;iostream&gt; using namespace std; int main() { for(int i = 0; i &lt;= 100; i++) { if(i % 2 != 0) { cout &lt;&lt; i &lt;&lt; endl; } } char wait; cin &gt;&gt; wait; return 0; }


What is the use of using namespace STD in c plus plus programming?

No, the use of 'namespace std' is not compulsory. You can specifiy it on any object reference. Specifying 'namespace' simply provides a default value. Contrast ... using namespace std; cout &lt;&lt; "Hello world!" &lt;&lt; endl; ... with ... std::cout &lt;&lt; "Hello world!" &lt;&lt; std::endl;