-
Unknown Compiling Error
"unterminated character constant"
it seems to be trying to get rid of all the strings where i use a ' between a " " i.e. "Someone's Something"
now this didn't happen until just a minute ago, so obviously i changed something, but i've checked and rechecked that all my " are closed and all my { have a }
i'll load the code up, maybe someone can compile it real quick and see what it is.
I'm using Dev C++ btw.
Thanx,
Darkflame
-
Whenever you use ' or " in a string, you need to place a backslash (\) before it. For example, on the line with the error, the string would be: "\'s Hitpoints:" instead of: "'s Hitpoints:".
-
If you do not treat them as escape characters, then they will be interpreted as the end of the string, and as you noticed, cause problems (in your case, the ending quotation mark created a new constant string which was not ended on that line).
-
Ok I tried that, but I still get the same error.
I changed the line from:
cout << "You Hitpoints: " << playerlife << '/' << playermaxlife << "\t\t" << enemyname << "'s Hitpoints:" << enemylife << '/' << enemymaxlife << '\n';
To:
cout << "You Hitpoints: " << playerlife << '/' << playermaxlife << "\t\t" << enemyname << "\'s Hitpoints:" << enemylife << '/' << enemymaxlife << '\n';
What gets me is this didn't happen until I added the trainlevel structure, which cotains nothing in it that i see would cause this.
Darkflame
-
You are missing the big point with cout!
ITS BUFFERED!
That basically means that cout has an internal buffer and the data in that buffer is not sent to the screen until one of these occur....
1) an endl ( not a \n)
2) a call to cin ( because cout is tied to cin)
3) a flush (i.e. cout<<"I'm getting better at c++"<<flush;)
4) the buffer is full.
-
So what's the solution? Do i add an endl to the end instead of \n?
Hmm this actually helped me solve another problem I had, but this one still exists. I don't get it.
Thanx,
Darkflame
-
try using the flush buffer.
-
Bah, I feel like an ass. Just ignore everything here.
If you look on line 911 You'll see i ended a " with a ' causing the error throught the program. So stupid, just goes to show hmm...
Thanx for trying to help,
Darkflame