String problem

closed account (jwkNwA7f)
When I display the string it displays something weird.

1
2
3
4
5
carry = worde[0];
worde.erase(0,1);
worde += carry;
worde += "ay";
cout << word;
00FD64C4


Thank you!
Show how worde is defined and what value it was assigned
By the way at first you are using variable with name worde but in the last statement you are outputing variable with name word. Is it a typo or you indeed output another variable by mistake?
Last edited on
closed account (jwkNwA7f)
I actually just fixed it, but I had the same problem in a hangman game I am working.

1
2
3
4
5
6
7

string guessingword[4] = {"_", "_", "_", "_"};
string wordanswer[1];
string wordtotal[1];
wordanswer[0] = wordlist[randword];
wordtotal[0] = guessingword[0] + guessingword[1] + guessingword[2] + guessingword[3];
cout << wordanswer;


The output was similar to the other one.

Thank you!
Last edited on
Yeah like vlad said, it looks like a type.
closed account (jwkNwA7f)
Hertz wrote:
Yeah like vlad said, it looks like a type.


Yes, that was the problem.
@cppprogrammer297


it is not clear what value randword has in the statement

wordanswer[0] = wordlist[randword];
closed account (jwkNwA7f)
Oh, It was:
int randword = rand() % 9;
closed account (jwkNwA7f)
Just fixed it again, sorry I put you to the trouble.

Thank you!
Topic archived. No new replies allowed.