C++ Me Need Help!

All questions regarding Windows programming, post here. API,COM, ActiveX, DirectX, OpenGL, MFC and so on...

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

C++ Me Need Help!

Postby Tracer » Sun Oct 05, 2003 7:09 pm

Why does C++ wait for 2 secs then all at once display FUDD!!? I know that this can be disabled in perl by setting the | variable to 0 (|=0), but how do I do this is C++?


------------------------
#include <iostream.h>
#include <windows.h>
int main()
{
Sleep(500);
cout<<"F";
Sleep(1000);
cout<<"U";
Sleep(1500);
cout<<"DD!!";
return 0;
}
-------------------------------


Plz help me im going crazy :shock:
Tracer
 

Postby Wizard » Sun Oct 05, 2003 9:08 pm

cout does not necessarily output everything right away.
use flush to empty the buffer like so.
Code: Select all
cout << "F" << flush;


I think that's right. Seems to work for me now.

You're also using outdated headers, but that's a seperate issue. If you don't know those, ask and it'll be told. If you do and don't care, then whatever.
User avatar
Wizard
Site Admin
 
Posts: 3226
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA

Postby Guest » Mon Oct 06, 2003 7:57 am

Plz elaborate on the outdated headers part, I would like to know more.
Guest
 

Postby Wizard » Tue Oct 07, 2003 9:25 am

Many of the old header files were standardized a few years back, so that a given set of instructions could be used regardless of which compiler you use. To differentiate between the old headers and the new ones, the .h was removed from them. So #include <iostream.h> is now just #include <iostream> as well as many others, I don't have the complete list, but it should be simple enough to google.
As well as the new headers was the inclusion of the standard namespace. Any objects in the new header files, such as cout and cin, are found in the namespace std, and can be accessed either individually, like so
Code: Select all
std::cout << "BLAH" <<std::endl;

or globally, by putting the following line under your includes
Code: Select all
#include <iostream>
using namespace std;
int main() {
// bunch of other code here
cout << "BLAH" << endl; // note I didn't put std::
// and any other code, whatever
};

then just using cout as normal, without the std:: in front. Namespaces are useful, but for a beginner who doesn't need to worry about them, just put the using line I mentioned early under your includes, and you shouldn't need to worry about it for now, just do some reading when you get the chance.
User avatar
Wizard
Site Admin
 
Posts: 3226
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA

Postby Tracer » Tue Oct 07, 2003 6:31 pm

Thank you for all of your help.
But, I would like to know what has been added in the new headers, and also some good reading on the whole topic. Thx in advance! :D
Tracer
 


Return to Windows Programming

Who is online

Users browsing this forum: No registered users and 0 guests