Difference between cout and std::cout
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.
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement