【发布时间】:2011-06-30 12:26:44
【问题描述】:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
char *charStr;
int stringLength;
void genRandom() {
static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < stringLength; ++i) {
charStr[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
}
charStr[stringLength] = 0;
}
int main()
{
while(true)
{
genRandom();
cout < charStr;
}
return 0;
}
编译时出现问题。它将编译得很好,但没有任何显示,然后程序将停止运行。所以我的问题是,这段代码有什么问题?
【问题讨论】:
-
问题不在于编译时。您似乎遇到了“运行时”错误。