View Full Version : Basic Bloodshed C++ kbhit() question
brizey
06-20-2006, 12:38 PM
Hello
=====
I have been using the latest version 5 Bloodshed dev-C++ compiler to do the following:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
while(!kbhit())
{
// make some coffee
}
system("pause");
return 0;
}
==========
I am sure this used to work fine .. but now it compiles, executes, gives me a blank screen .. but no amount of key pressing will stop the program.
Any ideas out there?
Thanks
=====
Melon00
06-20-2006, 03:46 PM
put a breakpoint at that system("pause") to see if you get there. If you do, try to put "pause" in all caps (not sure if this matters). Otherwise, I think you are stuck in an infinite loop somewhere in here:
while(!kbhit())
{
// make some coffee
}
Are you supposed to print anything in there?
brizey
06-20-2006, 03:53 PM
Yes ... but there is supposed to be an infinite loop here .. it should get broken when any key is hit ... thus breaking the while loop and finishing the program.
Of course I hope the program will do more than this, but this is the part that has me frustrated.
==
Brian
Melon00
06-20-2006, 04:17 PM
There is a bug in that loop then. You will need to post that loop if you want me to help you further.
brizey
06-20-2006, 05:10 PM
This is the brief program (.cpp just converted to .txt)
-- or you can just cut and paste the code from the posting.
Thanks for your trouble.
The following code works just fine with my version of Dev (Dev 5 beta (4.9.9.2)).
#include <iostream>
#include <conio.h>
using namespace std;
int main(int argc, char *argv[])
{
while(!kbhit())
{
// make some coffee
}
system("PAUSE");
return EXIT_SUCCESS;
}
Not sure where your problem lies. I started by making a new c++ console application project and used the above code. Everything worked as expected.
brizey
06-21-2006, 10:24 AM
Thanks for trying this. But this is really weird!
I have the same version of the compiler.
I created a console app and pasted your version over the top of what was there .. and I still get the same problem!
An infinite loop with a black window .. pressing keys has no effect!
Could I have done something silly to the settings within the compiler? Maybe I should reinstall it and try again.
brizey
06-21-2006, 11:59 AM
RESULT!
=====
Ah .. the problem seems to lie in the conio.h include file.
I replaced this with another version off the net and everything worked!
The only thing I can think of is that some time ago I installed some files off the net to enable the Borland graphics to work. So there must be a problem with the conio.h file that was substituted. Now of course with this new version the Borland graphics no longer work!! .. heh-ho.
If anyone has information on how to upgrade to the Borland graphics while still getting kbhit() to work properly, I would be very happy.
Thanks to all for their help.:rolleyes:
rpgfan3233
06-22-2006, 07:46 AM
Try using conio2.h (CONIO 2.0):
http://sourceforge.net/project/showfiles.php?group_id=115967&package_id=125853&release_id=257721
That URL will take you to the Devpak packaged version, which Dev-C++ 5 should have associated devpak files with Dev-C++ 5 during the install. I hope it works for you (it worked for me). And yes, it contains the Borland graphics functions.
brizey
06-22-2006, 12:10 PM
Thanks very much for this package information .. it looks like just what I am looking for.:)
nytrokiss
06-23-2006, 12:39 AM
kbhit isnt ANSI so you cannot use it the same on all compilers!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.