rickyjoepr
rickyjoepr

Reputation: 169

Blinking cursor on console during cout string

When the console opens and the program runs I only get a blinking cursor. Is there something that I am doing wrong? Is the program running too fast for me to see it?

Thank you for any help in advance.

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

Upvotes: 1

Views: 236

Answers (1)

Bill
Bill

Reputation: 14695

It looks like your while loop never exits:

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

You only update pos in the loop, but you don't use pos in the while condition.

Upvotes: 5

Related Questions