How to Include Cout in C++ Programs? [Closed]

How to Include Cout in C++ Programs? [Closed]

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??

5

3 Answers

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

0

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

1

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

1
Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.