C++ cout undeclared?

This is the first time this happened, my compiler (Dev-C++) says:
‘cout’ undeclared(first use this function)

The code is:

#inlcude <iostream>
#include <stdlib.h>
#include <conio.h>
#include <ctime>

using namespace std;

int main(){
int die1, die2, total, count, factor;

srand(time(NULL));
factor=time(NULL)%10000;
for (count = 0; count &lt; 10; count++){
    die1 = (rand()%6) + 1;
    die2 = (rand()%6) + 1;
    total = die1 + die2;
    cout &lt;&lt; total &lt;&lt; endl;   [B]// &lt;-- COUT UNDECLARED[/B]
};
getch();
return 0;

}

#include <iostream.h>

That should do it.

Goodluck

I haven’t programmed in C++ in awhile but wouldn’t this code work better:

#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <ctime>

int main()
{
int die1, die2, total, count, factor;

srand(time(NULL));
factor=time(NULL)%10000;
for (count = 0; count < 10; count++){
die1 = (rand()%6) + 1;
die2 = (rand()%6) + 1;
total = die1 + die2;
cout << total << endl;
}
getch();
return 0;
}

Don’t you mean ‘count’, not ‘cout’?

Douglas

No he doesn’t. And he doesn’t want iostream.h either. What version of Dev-C++ are you using?

I don’t remember if the current stable version includes a standards compliant compiler or not, but I know that the latest beta version does.

iostream.h is the old header, in which the namespace std is not declared. iostream is the new header, with which you should use the full namespace qualifier std::.

I suggest that you remove the line ‘using namespace std;’ and try to use std::cout instead.

Also you should remove the semicolon after the ending brace in the for-loop:


cout << total endl;
};

should be replaced with


std::cout << total << std::endl;
}

There is no need for std::count – The code I posted earlier works perfectly.

Not std::count, std::cout

<iostream.h> is the old, non-standard library which does not include the namespace std.
<iostream> is the new, standard library which does include the namespace std.

With any reasonably new compiler you should be using <iostream>, which means you either have to include a using namespace statement or fully qualify the object name (std::cout, std::endl in this case).

MaxS, your code works because you:

  1. Removed the trailing semicolon after the ending curly-brace in the for-loop
  2. Use the old, non-standard, iostream.h library. That means you don’t need to qualify the namespace (std::object or ‘using namespace std’).

It is a good idea to use the standardised libraries.

Ah… I see

I learned C++ with an old compiler :(. Oh well.

i just noticed that i wrote inlcude instead of include