-3

I'm I using terminal in ubuntu. I've installed g++ package for compiling c++ programs. But if I try to compile a program, it is giving an error that 'cout is not declared in this scope', even though I've included iostream header file. What should I do??

3 Answers3

3

Try using std::cout, instead of just cout.

Vince
  • 3,497
  • 2
  • 19
  • 15
2

Read in more detail about namespaces in c++. cout happens to be in the namespace called std.

After declaring your headers you can do using namespace std; and you don't have to use std::cout every time and use only cout, but that isn't suggested. instead you could declare only what you need.

ex: using std::cout; using std::cin; using std::string; that way you don't have to use std::cout everywhere in your code and use only cout or cin

Community
  • 1
  • 1
Udit Mukherjee
  • 687
  • 5
  • 20
-1

Maybe you don't have build-essential ? It's mandatory in order to compile correctly on ubuntu.

Ulamspi
  • 16
  • 2
  • @Ulamspi: If he has installed the `g++` package, then he has `libstdc++` already, as it is a dependency of `g++`; `build-essentials` isn't an additional requirement (although `build-essentials` is nice as it includes other useful tools). It is also not mandatory to have `build-essentials` to compile software with gcc. – Jason C Mar 29 '14 at 02:57