Sunday 28 December 2008

namespace

This is one of these annoying things that I keep forgetting and end up spending so much time trying to figure out what the problem is.


The Problem:

I am trying to compile a small piece of code I just wrote and get error messages like



error: `cerr' was not declared in this scope
error: `cout' was not declared in this scope
error: `endl' was not declared in this scope

I get these messages even though iostream is included!!!

The Solution:

The problem is due to the fact the cerr, cout, cin, endl and their freinds are defined in the std name space. Simply add the line:

using namespace std;

No comments:

Post a Comment