Teen Programmers Unite  
 

 

Return to forum top

C++ std::cout

Posted by mattlynam2002 [send private reply] at September 07, 2002, 07:27:43 AM

In c++ what's the point of using std::cout << ,when you can just put cout << ! What does std:: mean and do ?
p.s im just starting to program and dont know a thing yet !

Posted by regretfuldaydreamer [send private reply] at September 07, 2002, 08:54:41 AM

std is the standard namespace.

If your using <iostream.h> you shouldn't need the std, but if you are using <iostream> you should either write:

Std::cout ... on every line or
using namespace std;

I think.

Namespaces are ways of differenciating between two classes or methods of the same name.(Someone will provide a more correct version later).

Posted by taubz [send private reply] at September 07, 2002, 09:20:48 AM

So.... there might be a class named cout that exists in another namespace. You'd refer to that class as namespace2::cout. The std:: specifies that you're talking about cout in the std namespace.

using namespace cout; (which you put at the top of your file) means that if you don't specify a namespace when you refer to a class (just "cout"), the compiler will look in that namespace anyway to see if the class exists there. You can have any number of using namespace directives.

See the namespace keyword help.

- taubz

Posted by unknown_lamer [send private reply] at September 07, 2002, 02:34:50 PM

If you want to import a single symbol from another namespace into the current one you do:

 using NAMESPACE::SYMBOL 
So if you wanted to be able to do cout << ..., you have to do
 using std::cout; 
. Importing an entire namespace into the current one is not generally a good idea.
Posted by mattlynam2002 [send private reply] at September 08, 2002, 07:59:27 AM

Ahh i see! OK thanx all !

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.