Menu

keyboard buffer

Anonymous
2002-10-26
2012-09-26
  • Anonymous

    Anonymous - 2002-10-26

    I am new to C++ and I like Devc++, but I am tired of everytime, in my programs, I ask for input from the keyboard with getch() the next time I ask for input with 'cin >>', I have to backspace to delete the input from the getch().  Anyone have a solution?

    I have tried 'fflush(stdin)'  it doesn't work.

    HELPPPPPPP!!!!!

     
    • Nobody/Anonymous

      Put this before your cin
      cin.ignore(100, '\n');

      Curtis

       
    • Anonymous

      Anonymous - 2002-10-26

      here is a simple example:

      #include<iostream>
      #include<conio.h>

      int main()
      {

      char a,b;
      cout << "input a letter: ";
      a=getch();
      cout << "\ninput another letter: ";
      cin.ignore(100, '\n');
      cin >> b;

      cout << "a= " << a << " b= " << b;
      getch();
      return 0;
      }

      I don't want  to print the character from the getch()
      at the next  cin.  I tried your suggestion, it does ignore it but it still prints it there

       
    • Anonymous

      Anonymous - 2002-10-26

      Curtis thanks for your help.

      I figured it out I think.

      I added:

      int k=getch();//a dummy input

      to catch the last key stroke.

      it seemed to work for my program.

      thanks again.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.