Difference between cout and std::cout?

I dont know when to use "cout" and when to use "std::cout".
Sometimes I get error when I use "cout" and sometimes when I use "std::cout"
Can you help me please?
std is the name of a namespace.

Everything in the C++ library is (or should be) defined inside the std namespace.

You can write simply cout instead of std::cout usually after you've done:
using namespace std;

// or

using std::cout;

You are advised to avoid using namespace std; and always explicitly use std:: in order to avoid name collisions.

Last edited on
closed account (zb0S216C)
"cout" implies that you've told the compiler that you're "using" "cout" at some point. Any references to "cout" will cause the compiler to locate that identifier (or symbol) by resolving its scope; the compiler will search both the global name-space and the "std" name-space if you "#included <iostream>".

With "std::cout", however, the compiler knows exactly where to look for "cout". So in effect, qualifying "cout" with "std" helps the compiler by eliminating guess-work.

Last edited on
Thank you all for the quick help :)
Topic archived. No new replies allowed.