Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'cout' was not declared in this scope [closed]

Tags:

c++

iostream

cout

People also ask

How do I fix cout was not declared in this scope?

Use std::cout , since cout is defined within the std namespace. Alternatively, add a using std::cout; directive.

Why is cout not working in C++?

In a windowing system, the std::cout may not be implemented because there are windows and the OS doesn't know which one of your windows to output to. never ever give cout NULL. it will stop to work.

How do I fix CIN was not declared in this scope?

You have to include the <iostream> header in your source code, since the header provides the input and output streams, i.e. contains cin and cout functionalities. Hope this helps. Else, you may have to provide your code for further inspection. cin and cout are defined in the scope of namespace std.


Put the following code before int main():

using namespace std;

And you will be able to use cout.

For example:

#include<iostream>
using namespace std;
int main(){
    char t = 'f';
    char *t1;
    char **t2;
    cout<<t;        
    return 0;
}

Now take a moment and read up on what cout is and what is going on here: http://www.cplusplus.com/reference/iostream/cout/


Further, while its quick to do and it works, this is not exactly a good advice to simply add using namespace std; at the top of your code. For detailed correct approach, please read the answers to this related SO question.


Use std::cout, since cout is defined within the std namespace. Alternatively, add a using std::cout; directive.