A few problems with the code:
cout < charStr;
it should be:
cout << charStr;
If you compile the g ++ -Wall argument (all warnings), this error becomes apparent.
, stringLength! , - . stringLength - 0, . undefined , , (, , , ).
:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
int stringLength = sizeof(alphanum) - 1;
char genRandom()
{
return alphanum[rand() % stringLength];
}
int main()
{
while(true)
{
cout << genRandom();
}
return 0;
}
- , , . , , char *, , . , ++ ++, - .