I've got a problem with my function that's supposed to generate a vector of random strings. However, all I get is the first element in the vector is random and the rest is empty. Here's the code:
void losuj(vector <string> &vec, int ile){
int i, j;
string str;
stringstream ss;
char c;
for(i=0; i<ile; i++){
for(j=0; j<5; j++){
c= rand()%25 + 97;
ss << c;
}
ss >> str;
vec.push_back(str);
ss.str().clear();
str.clear();
}
}
Any thoughts on what could be wrong?
ss.str()just return a string, instead of anything else? callingclearon that wouldn't do too much, I think?strinside outer for-loop usingstr.append(c)would be sufficient. And<random>would make this much cleaner, btw.<random>.