Click here to Skip to main content
16,016,489 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: api subversion Pin
S Douglas20-Oct-05 0:24
professionalS Douglas20-Oct-05 0:24 
QuestionExchange data between PropertyPages Pin
emma200019-Oct-05 1:26
emma200019-Oct-05 1:26 
AnswerRe: Exchange data between PropertyPages Pin
prasad_som19-Oct-05 2:02
prasad_som19-Oct-05 2:02 
AnswerRe: Exchange data between PropertyPages Pin
David Crow19-Oct-05 3:33
David Crow19-Oct-05 3:33 
GeneralRe: Exchange data between PropertyPages Pin
kiran janaswamy19-Apr-06 19:21
kiran janaswamy19-Apr-06 19:21 
QuestionRe: Exchange data between PropertyPages Pin
David Crow20-Apr-06 2:50
David Crow20-Apr-06 2:50 
AnswerRe: Exchange data between PropertyPages Pin
PJ Arends19-Oct-05 5:28
professionalPJ Arends19-Oct-05 5:28 
Questionproblem with _kbhit and i/o exception handling Pin
codeingit19-Oct-05 1:24
codeingit19-Oct-05 1:24 
hi,
I want to generate random numbers in c++ (using vc++ 6.0) on hit of enter. I am using _kbhit(), but don't know how to reset it, so that I can use it again, can anybody help me with this.
code is say like following.


#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace::std;


int main(int argc, char* argv[])
{
for(int i=0; i<10; i++)
{
cout << "hit enter to generate random number" << endl;
int ran1 = func1();
cout << "hit enter to generate random number" << endl;
int ran2 = func2();
}

return 0;
}


int func1()
{
int ret;

while(!_kbhit())
{
ret = rand()%10;
Sleep(1000);
}
return ret;
}


int func2()
{
int ret;

while(!_kbhit())
{
ret = rand()%20;
Sleep(1000);
}
return ret;
}

There is another problem with I/O exception handling:
i tried to read an int correctly using following code. but in case of exception it is caught but cin doesn't execute inspite of clearing it:

int main(int argc, char* argv[])
{
int i;
bool check = false;

cin.exceptions(ios_base::failbit);

while(!check)
{
try{
cout << "enter a number: ";
cin >> i;
check = true;
}catch(ios_base::failure){
cin.clear();
}

}

return 0;
}

Thanks,
vikas
AnswerRe: problem with _kbhit and i/o exception handling Pin
John R. Shaw19-Oct-05 10:05
John R. Shaw19-Oct-05 10:05 
Questionhow to add a new device and uninstall it in MFC? Pin
V.G19-Oct-05 0:59
V.G19-Oct-05 0:59 
QuestionPARALLEL CONTROL Pin
eriq19-Oct-05 0:50
eriq19-Oct-05 0:50 
AnswerRe: PARALLEL CONTROL Pin
vikas amin19-Oct-05 3:05
vikas amin19-Oct-05 3:05 
QuestionHow to map keyboard Event in a Dialogbar Pin
Manohar B. Srikanth19-Oct-05 0:35
Manohar B. Srikanth19-Oct-05 0:35 
QuestionCan Someone Explain Error Message Pin
sweep12319-Oct-05 0:21
sweep12319-Oct-05 0:21 
AnswerRe: Can Someone Explain Error Message Pin
toxcct19-Oct-05 0:26
toxcct19-Oct-05 0:26 
GeneralRe: Can Someone Explain Error Message Pin
sweep12319-Oct-05 0:45
sweep12319-Oct-05 0:45 
GeneralRe: Can Someone Explain Error Message Pin
prasad_som19-Oct-05 2:11
prasad_som19-Oct-05 2:11 
GeneralRe: Can Someone Explain Error Message Pin
toxcct19-Oct-05 2:28
toxcct19-Oct-05 2:28 
GeneralRe: Can Someone Explain Error Message Pin
prasad_som19-Oct-05 2:42
prasad_som19-Oct-05 2:42 
GeneralRe: Can Someone Explain Error Message Pin
Rage19-Oct-05 3:16
professionalRage19-Oct-05 3:16 
GeneralRe: Can Someone Explain Error Message Pin
sweep12319-Oct-05 3:33
sweep12319-Oct-05 3:33 
GeneralRe: Can Someone Explain Error Message Pin
toxcct19-Oct-05 3:52
toxcct19-Oct-05 3:52 
GeneralRe: Can Someone Explain Error Message Pin
sweep12319-Oct-05 4:04
sweep12319-Oct-05 4:04 
GeneralRe: Can Someone Explain Error Message Pin
Roger Stoltz19-Oct-05 3:47
Roger Stoltz19-Oct-05 3:47 
GeneralRe: Can Someone Explain Error Message Pin
John R. Shaw19-Oct-05 10:23
John R. Shaw19-Oct-05 10:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.