cout not declared?

I'm teaching myself and bought a c++ compiler and I can't figure out why this cout is not declared.

1
2
3
4
5
6
Int main ( ) {
Int a = 5;
Int b = 3;
If ( a > b ) {
Cout << " its not declared?";}
Return 0; }


My app gives an error saying cout is not declared. Help please?
Last edited on
closed account (2LzbRXSz)
Do you have

1
2
3
#include <iostream>

using namespace std;


At the top of your code?

Edit:
C++ is case sensitive. The "C" in cout should not be capitalized (return and if shouldn't be capitalized either).
Last edited on
Forgot iostream... facepalm thank you so much haha

Edit: yeah its autocorrect I'm learning and using my driod lol... but everything is lowercase inside the app. Thanks again.
Last edited on
closed account (2LzbRXSz)
No problem :)
No. No using namespace std;. Bad habit. Do not learn.

If you use cout only once, then write std::cout.

If you use cout multiple times in main(), then write:
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

int main() {
  using std::cout; // function scope
  // other code
  cout << "Hello ";
  // other code
  cout << "Dolly!\n";
  // other code
  return 0;
}


If you use cout in many functions, then:
1
2
3
4
#include <iostream>

using std::cout; // file scope


Only in the most narrow scope and only the necessary symbols.


bought a c++ compiler

There are many, good, free C++ compilers.
Last edited on
closed account (2LzbRXSz)
Ah, thank you. A lot better of a solution. I've sort of fallen into that bad habit from just being taught wrong from the start, and then forgetting it was a bad habit. I learned coding with the mindset that "std:: is only for super professional code. Just use the namespace std!" and never bothered to correct it.

And I agree. Which compiler did you buy, if you don't mind me asking?
Why is using namespace std; a bad idea/habit?
closed account (2LzbRXSz)
Things can get pretty messed up.
The first two answers do a pretty good job of explaining how things can go south, and most of the time without you even realizing!
http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
Topic archived. No new replies allowed.