0

I am getting the error "Error: 'cout' was not declared in this scope," but I included <iostream>, which was the solution that was given for similar problems in my research. My code is this:

#include <iostream>
int main(){

    Sally so;
    Cout << "omg wtf is this on my shoe" << endl;
}
Allen
  • 35
  • 3

3 Answers3

5
  1. Its cout not Cout, notice the case difference.
  2. cout is in the namespace std. In order to use it you need to resolve the namespace with std::, so use std::cout << ....
  3. As much as people will tell you to just do using namespace std, dont. For more info, see Why is “using namespace std” considered bad practice?.
Community
  • 1
  • 1
Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175
2
  1. You are writing "Cout" not "cout" - C++ is case sensitive, so those two are not the same thing.

  2. You should write std::cout since the cout stream lives in the std namespace.

  3. The same goes for endl which should be std::endl.

You could avoid writing std:: by using using namespace std; but I wouldn't advice it - it pulls all of the namespace into the current scope which may not hurt for a trivial program will bite for a more complex one (at the very least, don't do it in headers).

Just do this:

#include <iostream>
int main(){
    Sally so;
    std::cout << "omg wtf is this on my shoe" << std::endl;
}

Btw; unless you know you want to flush the stream, prefer '\n' over std::endl.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
-1

Change your code to this:

#include<iostream>
using namespace std;
int main()
{
    Sally so;
    cout<<"the text"<<endl;
}    

Hope it helps!! Cheers

ba11b0y
  • 161
  • 3
  • 18