Jump to content
  • Advertisement
Sign in to follow this  
Jovan

Difference between cout and std::cout

This topic is 5432 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This new book i am reading on C++ begins cout and vector and such with std:: however, when i try to compile it in visual C++ 6, it gives me an error. What should i include, and what is the difference? =\ thnx.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Jovan
This new book i am reading on C++ begins cout and vector and such with std::

however, when i try to compile it in visual C++ 6, it gives me an error. What should i include, and what is the difference? =\


thnx.


in ANSI/ISO C++ there are "all" containers defined in "namespace std" and headers are without extensions (e.g. iostream, string, etc.). HelloWorld example looks than as follows:

#include <iostream>

int main(int argc, char ** argv)
{
std::cout << "Hello, world!" << std::endl;
return 0;
}



if you'd like to do not use that boring "std::cout" with every STL container, try keyword "using":

#include <iostream>

int main(int argc, char ** argv)
{
using std::cout;
using std::endl;

cout << "Hello, world!" << endl;
return 0;
}



however, NEVER do this:

#include <iostream>
using std;

int main(int argc, char ** argv)
{
cout << "Hello, world!" << endl;
return 0;
}


because namespaces are then losting their sense. [wink]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!