Jump to content
  • Advertisement
Sign in to follow this  
v0dKA

Weird std::cout Error [resolved]

This topic is 5203 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have no idea what went wrong or how. I'm writing QuizzerApp - it reads a .txt file as a special "quiz file", which has different sorts of questions and their answers - basically, that .txt is a quiz. The problem comes in when I std::cout a question and its asnwer choices. For some reason, it works when I output a fill-in question to the screen, but not the multiple choice. In detail, the problem is with the endl's. Instead of ending a line, it spits out something hexadecimal. It also messes up previous calls to std::cout. There's about 10 statements I need to output. The first 5 belong to the fill-in group, which works fine alone. The second 5 have the weird error. Also, for some weird reason, instead of the statements getting outputted in order, as in {1,2,3,4,5,6,7,8,9,10}, something totally weird happens: {1,2,5,6,7,8,3,4,5,9,10}. And once again, I get junk instead of endl. Need I post my code, or does this problem sound familiar to someone? [Edited by - v0dKA on September 12, 2004 4:37:27 PM]

Share this post


Link to post
Share on other sites
Advertisement
I don't mix printf and cout, although I may have mixed \n and endl...

EDIT: Never mind, I only used endl.

EDIT 2:

There's too much code to post, but here's a possible cause of the error. I do cout std::string's, but I use their c_str() method, as in:

std::cout << endl << SomeSTDstring.c_str();

But that would result in something hexadecimal, followed by the actual string. Weird, stupid error. Me no like.

EDIT 3: OK, here's the code which messes up all:

bool AskQuest()
{
RandomizeChoices();
std::cout << endl;
std::cout << Question.c_str();
std::cout << endl
<< Choices[ ChoiceOrder[ 0 ] ].c_str() << " "
<< Choices[ ChoiceOrder[ 1 ] ].c_str();
std::cout << endl
<< Choices[ ChoiceOrder[ 2 ] ].c_str() << " "
<< Choices[ ChoiceOrder[ 3 ] ].c_str();
std::cout << endl
<< "Answer: ";

cin >> guess;

if( AnsCompare() )
return true;
else
return false;
}




I divided up the cout statements into multiple statements, in case that was the cause. All variables are declared.

Share this post


Link to post
Share on other sites

Question, Why are you mixing std::cout calls with non std endl and cin?

without using the std namespace all of those should require std:: to prefix them. Yet your posted code doesn't. Which should give you an error at compile time.

soo umm ya.

Rigear

Share this post


Link to post
Share on other sites
Quote:
Original post by Rigear

Question, Why are you mixing std::cout calls with non std endl and cin?

without using the std namespace all of those should require std:: to prefix them. Yet your posted code doesn't. Which should give you an error at compile time.

soo umm ya.

Rigear


...Oh

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!