Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

need help on bug

The following is part of my code. The program keeps falling through cin and getch() without any input.

It then falls through and keeps doing a loop. I set the loop up and put the sleeps in to test to see if it was falling through. Any ideas?


char move;
cout << "before cin
";
Sleep(1000);
cin >> move;
cout << "after cin
"; Sleep(100);cout <<move;
getch();
cout <<move<<endl;
cout << "after getch
"; Sleep(1000);

Comments

  • gautamgautam Member Posts: 642
    Hi,

    Can you explain more clearly ? I did not understand your question at all. Also can we see the loop code. or the whole function code. And why not use getchar to get the character instead of cin ??

    char move = getchar();


    : The following is part of my code. The program keeps falling through cin and getch() without any input.
    :
    : It then falls through and keeps doing a loop. I set the loop up and put the sleeps in to test to see if it was falling through. Any ideas?
    :
    :
    : char move;
    : cout << "before cin
    ";
    : Sleep(1000);
    : cin >> move;
    : cout << "after cin
    "; Sleep(100);cout <<move;
    : getch();
    : cout <<move<<endl;
    : cout << "after getch
    "; Sleep(1000);
    :

  • Johnny13Johnny13 Member Posts: 128
    [b][red]This message was edited by Johnny13 at 2004-12-21 3:31:32[/red][/b][hr]
    : : char move;
    : : cout << "before cin
    ";
    : : Sleep(1000);
    : : cin >> move;
    : : cout << "after cin
    "; Sleep(100);cout <<move;
    : : getch();
    : : cout <<move<<endl;
    : : cout << "after getch
    "; Sleep(1000);

    Bah! thats why C++ Is Ugly and confusing people! http://virtus.ath.cx/texts/ugly.html
    sorry,have to ;P
  • XLoomXLoom Member Posts: 129
    You are writing a console application? Otherwise getch(), getchar() and cin-cout do not work.

    Another possibility is, that if this code is executed immediately after starting the program, perhaps for some reason the keyboard buffer still holds some keys. Although I doupt it, since you have multiple functions attempting to get input. Try getting multiple getch() values and see if it these are 0 or something else.

    XLoom

    PS
    C++ is not ugly and it is only confusing, just like any other programming language, to people who have not learned to use it properly.
  • amsams Member Posts: 25
    : You are writing a console application? Otherwise getch(), getchar() and cin-cout do not work.
    :
    : Another possibility is, that if this code is executed immediately after starting the program, perhaps for some reason the keyboard buffer still holds some keys. Although I doupt it, since you have multiple functions attempting to get input. Try getting multiple getch() values and see if it these are 0 or something else.
    :
    : XLoom
    :
    : PS
    : C++ is not ugly and it is only confusing, just like any other programming language, to people who have not learned to use it properly.
    :


    try using flush() b4 getch()...
Sign In or Register to comment.