-
Delayed Functions?
Code:
#include <stdlib.h>
#include <time.h>
#include <iostream.h>
#include <string.h>
#include "Console.h"
namespace con = JadedHoboConsole;
inline void drawline(int length)
{
int i;
for (i=0; i<length; i++)
{
cout << (char)205;
}
}
// Main Menu
void menu()
{
// Clear Screen
using std::cout;
using std::endl;
cout << con::clr;
cout << (char)201;
drawline(20);
cout << (char)203 << endl;
cout << (char)186 << "(L)2005" << char(186) << "Blah Blah Blah" << endl;
cout << (char)204;
}
int main()
{
menu();
return 0;
}
This code compiles fine (no warnings) but when executed, the function drawline is not called until after all the other couts. Any idea on what the problem is?
-
You probably need an endl in the function. I've had similar out-of-sequence problems when I used '\n' in place of 'endl'. endl flushes the buffer. \n does not. Try putting this line: cout << (char)203 << endl; into your drawline() function.
I don't know why this happens... I'm sure your program is executing in the correct sequence. It's just that the output is not gettting displayed in the correct sequence. I believe this is an operating system issue... maybe Windows has multiple stdout buffers???
-
If it's out of sequence them something if very wrong (and unlikely).
The output probably just hasn't been flushed to the screen as DougDbug suggested. You can also flush the stream without adding a newline like so: "cout << flush;".
gg
-
I have the same problem with MessageBox();
Code:
cout << "I love you......";
cout << "a lot.";
MessageBox(0,"I love you.","Guess what?",0);
The message box will pop up before the cout messages are displayed.
-
whoa. flush; worked like a charm. thanks a bunch guys.