Advertisement

Problem with if

Started by January 31, 2002 09:33 PM
5 comments, last by StoNeD_TrOLL 22 years, 7 months ago
Okay,I am having a problem ending this if statement.My complier puts whatever is after my if statement in the statement.Heres the code: if (ank == 7) std::cout<<"_X_|___|___\n"; std::cout<<"___|___|___\n"; std::cout<<"___|___|___\n"; std::cout<<" | |\n"; so how do i end it?
Enclose everything inside the if statement in braces {}. So ...
if (ank == 7)
{
std::cout << "blah\n";
...
...
}
std::cout << "We are no longer in the if statement\n";
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Advertisement
That dosent work.
quote: Original post by StoNeD_TrOLL
That dosent work.

It should. What''s wrong with it?

Flush the buffer. (ie, cout << endl; or cout << flush;)

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
I though flush only cleared the input buffer? Or is it just one general buffer. I always use endl tho...

Drew Sikora
Executive Producer
GameDev.net

Advertisement
Remember that cout, cin, fstream, ofstream, ... are all subclasses of iostream/iobase (or something like that anyway). so most funcs can be used accross the board and will achive similar results.

this is foolproof and if it doesn't work check your compiler settings (i'll be assuming that you're in std namespace 'using namespace std;' for simplicity):

if (ank == 7) {
cout << "_X_|___|___\n";
cout << "___|___|___\n";
cout << "___|___|___\n";
cout << " | |\n";
}
or you could take a small shortcut:

if (ank == 7) {
cout << "_X_|___|___\n"
<< "___|___|___\n"
<< "___|___|___\n"
<< " | |"
<< endl;
}

Edited by - Krysole on February 2, 2002 11:27:20 PM

This topic is closed to new replies.

Advertisement