2015-05-11 118 views
1

当控制台打开并且程序运行时,我只能看到一个闪烁的光标。 有什么我做错了吗?程序运行速度太快,我看不到它?cout字符串期间在控制台上闪烁光标

感谢您提前给予任何帮助。

#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

您的'RandomString'函数不会将任何字符添加到'str'。它永远不会回来。 –

回答

5

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

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

您只需更新循环pos,但你不要在while条件下使用pos