Thread: Non-Blocking-Input And Overwriting-Output

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    265

    Non-Blocking-Input And Overwriting-Output

    Ok, here is my 2 part question.

    How do i set cout (preferably) to overwrite previous text. eg:
    Code:
    std::cout << "i like bob" << std::endl;
    std::cout << "i hate";
    i want to print out: "i hate bob\n". Each line overwriting previous console text.

    Second Part: Non-Blocking-Input.
    If that title makes no sense, dont worry, i made it up because i couldnt think of a better name for it. I want to get a keypress, IF there is a keypress, and NOT halt the program to wait for one. If there is a better term for this please let me know. Would a local keyhook do this for me? If there is an easier not-so-platform-specific way to get this style of input, please tell me all you know.

    As always, thanks for your time.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Part 1:
    Code:
    #include <iostream>
    
    int main(void)
    {
      std::cout << "i like bob" <<std::flush;
      std::cout << "\ri hate";
      return(0);
    }
    Better ways to do this are going to be compiler dependant. In fact, this goes for part 1 and part 2.

    Part 2:
    If you have kbhit(), use it. Else, post your compiler details.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    265

    your right.

    Your right, im sorry, i should add it to my signature because i never bother to post it. Im running MS VC++ 6.0 on my 2k workstation, and on the other video input im running FreeBSD 4.8, with gcc 2.95.4.

    What does std::flush do?

    Can you provide a simple example of kbhit?

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    std::flush simply flushes the output stream. std::endl does this too, but it also moves the cursor to the next line, which you didn't want to do.

    As for kbhit(), just do a search
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed