# 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.

## 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 on other sites
post code, unless you're mixing printf and cout, which is a bad idea.

##### 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 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 on other sites
Quote:
 Original post by RigearQuestion, 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

Works now?

yes.

##### 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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628645
• Total Posts
2984015

• 9
• 9
• 10
• 21
• 20