is picking a rand() value wich is used for rand element index from a string array, that holds many words. 22 is just the maxoffset of rand().
is returning the picked word
So this first code is getting the lenth of a string and randWord without a problem. Also it prints its elements in the right way.
Code:
Set_randWord(22);
int len = Get_randWord().size();
cout << len << endl; //<-- lenth of word is OK
cout << Get_randWord() << endl; //<-- return a word is OK
for (int i = 0; i < len; i++){
hiddenWord[i] = '_'; //<-- hiddenWord declared in the class .h
cout << hiddenWord[i] << " ";
}
hiddenWord[len] = '\0';
So the second code, the only difference is that the lenth variable of word is previously declared in the class.h
Code:
Set_randWord(22);
lenofWord = Get_randWord().size(); //<-- lenofWord declared in .h
cout << lenofWord << endl; //<-- lenth of word is OK
cout << Get_randWord() << endl; //<-- return a word is OK
for (int i = 0; i < lenofWord; i++){
hiddenWord[i] = '_';
cout << hiddenWord[i] << " ";
}
hiddenWord[lenofWord] = '\0';
In the second code i get exactly 195 '_' characters no matter how ,uch the lenth of the word is or the random word itself, 195 '_' are printed.
The difference i noticed is only that i change with previously declared Ty for reading!