Difference between cout and std::cout

Started by
2 comments, last by Triglav 19 years, 7 months ago
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.
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]
Triglav - Member of TAJGA Team
Thank you :) i get it.
damn!
replace "using std;"
with "using namespace std;"
Triglav - Member of TAJGA Team

This topic is closed to new replies.

Advertisement