English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

what does it do? Is this code a recent addition? I had started C++ 2 years ago and then switched to java .Back then nobody tought me to use it("using namespace std;") ever not even once.Was my teacher dumb??
and the compiler i use says"Namespace name expected " every time i include this peice of code in the program.The compiler i use is Borland C++ version 5.03 .Is it a source of the problem??help me out guys.

2006-10-03 22:21:29 · 2 answers · asked by Sakar 1 in Computers & Internet Programming & Design

2 answers

Without getting too complicated -- basically they have created a way in C++ to differentiate between different areas of "namespace" in such a way that you could potentially have multiple objects or typedefs, etc of the same name that don't overlap. The "std" namespace is where most things in the C++ header files (iostream for example) live.

For example I could create a class and call it "string", even though a class called "string" already exists, if I put it in a different namespace.

I would guess that you are using something like a cout, cin, endl, string, or other predefined type/object. "cout" for example is actually called "std::cout", but by putting "using namespace std;" you are able to leave off the "std::" part.

2006-10-03 22:38:02 · answer #1 · answered by Jason M 2 · 0 0

"namespace" is the essential part of C++. To understand what any namespace means (as e.g. namespace std), just read any C++ book.

2006-10-04 00:11:19 · answer #2 · answered by alakit013 5 · 0 1

You might like to read this for a decent introduction to namespaces:

http://www.glenmccl.com/ns_comp.htm

I would recommend switching back to C++ and leaving Java well alone - better to learn to use a tool than a toy.

Rawlyn.

2006-10-03 22:41:28 · answer #3 · answered by Anonymous · 0 0

some classes etc. are declared in _namespaces_, std - is one of that nmespaces. To access that class you need resolve the namespace.
Taht could be performed with: using namespace xxxx; (as an option)
For instance:

#include
#include
using namespace std;
....
vector v;
map m;
********************** or *****************

#include
#include
....
std::vector v;
std::map m;
--------------------------------------------------
good luck

2006-10-03 23:34:39 · answer #4 · answered by Ugi 2 · 1 0

fedest.com, questions and answers