当控制台打开并且程序运行时,我只得到一个闪烁的光标。 有什么我做错了吗?程序运行得太快,我看不到它?
感谢您提前提供任何帮助。
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
string RandomString(int len)
{
srand(time(0));
string str = "01213456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int pos;
while (str.size() != len) {
pos = ((rand() % (str.size() - 1)));
}
return str;
}
int main()
{
string random_str = RandomString(10);
cout << "random_str : " << random_str << endl;
system("pause");
return 0;
}
答案 0 :(得分:5)
看起来你的while
循环永远不会退出:
while (str.size() != len) {
pos = ((rand() % (str.size() - 1)));
}
您只能在循环中更新pos
,但不能在pos
条件下使用while
。