Sign in to follow this  

Weird std::cout Error [resolved]

This topic is 4838 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
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

This topic is 4838 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this