i am new with c++ and as i was going through all the post i found a reserved word i.e.
namespace. i am unable to know what do u mean by this and as i was trying to run the program there was a error telling "namespace name required". i used namespace in such a way using namespace std;
plz help

namespace is a keyword in standard C++ that indicates a container of information. For example, namespace std contains all the standard header files such as iostream, cctype, string, cmath, etc and their contents such as cin, cout, and the int, float, char types, etc. You can declare your own namespaces just like you can create your own variables, functions, types, etc, and you can store basically whatever you want in them.

Once something is in a namespace you need to have a way to get them out again; or to refer to them, if you will. This is done with either a using statement or the scope operator preceded by a namespace name. So, in order to use something like the cout object from namespace std you could do this:

#include <iostream>
using namespace std;
int main(){cout << "hi";}

or this:

#include <iostream>
using std::cout;
int main() {cout << "hi";}

or this:

#include <iostream>
int main() {std::cout << "hi";}

>there was a error telling "namespace name required"
Post your code.

Well if you Google "namespace in C++" you'll get a lot of information about it. However, namespace is a collection of classes. to get a proper output you have to use that. By using using namespace std; you remove the use of using std in all of the other places inside the code.

#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World!";
}

can also be written as :

#include<iostream>
int main()
{
std::cout<<"Hello World!";
}

This just helps us not to remember using std in every default function listed in std.

Oops.. Sorry didn't saw the already posted posts, I guess had this tab opened for a long time -_-' Sorry.
Also the compile won't show you namespace requred, it'll only point out that the functions unidentified.

taking the above code

#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World!";
}

-by chasevoid
when i executed this code there was a error saying namespace name excpeted.

which compiler are you using?

i checked it should work perfect there might me something wrong with ur compiler.

Which one r u using?

i am using borland c++ ver 5.0

>i am using borland c++ ver 5.0
Are you sure you have all the libraries installed. check that, if it doesn't work, try some other compilers. Because the code is correct.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.