What is std:: ?

C

ComicCaper

Hi all,

Ok, my class book doesn't cover this yet I see it being used with very
basic statements such as cout. It is also covered in other C++ books in
the first program (I was skimming at Borders) so what does it actually
do? And you can imagine the results I get when putting std into google.

Thanks,

Matt
 
A

Alf P. Steinbach

* ComicCaper:
Hi all,

Ok, my class book doesn't cover this yet I see it being used with very
basic statements such as cout. It is also covered in other C++ books in
the first program (I was skimming at Borders) so what does it actually
do? And you can imagine the results I get when putting std into google.

"std::whatever" refers to a name "whatever" from the standard library.

Technically it states which namespace (namely, "std") the name is
defined in, or at least is available in.

That helps to avoid name collisions: you can have the same name, with
different meanings, in different namespaces.
 
P

Phlip

ComicCaper said:
Ok, my class book doesn't cover this yet I see it being used with very
basic statements such as cout. It is also covered in other C++ books in
the first program (I was skimming at Borders) so what does it actually do?
And you can imagine the results I get when putting std into google.

All the Standard Library identifiers are in a namespace called std. Googling
"namespace std" with quotes gives this first good hit:

http://www.cplusplus.com/doc/tutorial/namespaces.html

You need to suspect your class and tutorial if it doesn't cover these
things. They have been the de-facto standard for >10 years now.

Whether you suspect your class or not, always learn anything - especially
C++ - from many more sources than an assigned textbook.
 
B

benben

ComicCaper said:
Hi all,

Ok, my class book doesn't cover this yet I see it being used with very
basic statements such as cout. It is also covered in other C++ books in
the first program (I was skimming at Borders) so what does it actually
do? And you can imagine the results I get when putting std into google.

Thanks,

Matt

As to the googling part: you can easily get useful descriptions by
searching "c++ std", "std:: c++" "namespace std:: c++", etc.

I admit that the use of the abbreviation is odd. Funny in a sense that
abbreviation itself presents an embarrassing name collision--the very
thing that it tries to avoid :)

Regards,
Ben
 
W

wgebers

from a practical point of view. If you not already using std::cout
then you probably have a line at the top of your code ' using namespace
std' Basically this line of code tells the compiler that you are using
the standard library and wherever it sees cout it must assume you mean
std::cout.
 
R

Richard Herring

from a practical point of view. If you not already using std::cout
then you probably have a line at the top of your code ' using namespace
std' Basically this line of code tells the compiler that you are using
the standard library and wherever it sees cout it must assume you mean
std::cout.

No, that would be "using std::cout;". "using namespace std;" is more
general than that. Wherever it sees a name it will now look in std _as
well as_ everywhere else it would search. If you have an object called
cout in some other namespace, it may find that instead - the rules are
complicated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top