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 Answers
Try using std::cout, instead of just cout.
Read in more detail about namespaces in c++. cout happens to be in the namespace called std.
After declaring your headers you can dousing 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
Maybe you don't have build-essential ? It's mandatory in order to compile correctly on ubuntu.