String problem

Jul 28, 2013 at 6:29pm
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!
Jul 28, 2013 at 6:35pm
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 Jul 28, 2013 at 6:39pm
Jul 28, 2013 at 6:43pm
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 Jul 28, 2013 at 6:47pm
Jul 28, 2013 at 6:43pm
Yeah like vlad said, it looks like a type.
Jul 28, 2013 at 6:45pm
closed account (jwkNwA7f)
Hertz wrote:
Yeah like vlad said, it looks like a type.


Yes, that was the problem.
Jul 28, 2013 at 6:48pm
@cppprogrammer297


it is not clear what value randword has in the statement

wordanswer[0] = wordlist[randword];
Jul 28, 2013 at 6:48pm
closed account (jwkNwA7f)
Oh, It was:
int randword = rand() % 9;
Jul 28, 2013 at 7:13pm
closed account (jwkNwA7f)
Just fixed it again, sorry I put you to the trouble.

Thank you!
Topic archived. No new replies allowed.