gpt4 book ai didi

c++ - cout 字符串期间控制台上闪烁的光标

转载 作者:行者123 更新时间:2023-11-30 01:14:28 29 4
gpt4 key购买 nike

当控制台打开并且程序运行时,我只看到一个闪烁的光标。我做错了什么吗?程序运行速度太快,我看不到吗?

提前感谢您的帮助。

#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;
}

最佳答案

看起来你的 while 循环永远不会退出:

    while (str.size() != len) {
pos = ((rand() % (str.size() - 1)));
}

您只在循环中更新 pos,但在 while 条件中不使用 pos

关于c++ - cout 字符串期间控制台上闪烁的光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30174344/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com