Thread: Single unbuffered input in C++

  1. #1
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350

    Single unbuffered input in C++

    Have any of you gurus come up with a method of obtaining unbuffered input in C++ using iostream.h alone?

    I've searched the board.
    http://cboard.cprogramming.com/searc...der=descending

    I thought I could do it with some inline asm but VC 6 and my other 32 bit compilers lock up at execution time... blasted WinAPI. This is for a console app.

    TIA

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Well, you could make it a win32 app and receive char messages.

    Why would you want to do this?

  3. #3
    Registered User nag's Avatar
    Join Date
    May 2002
    Posts
    22
    I have not worked this problem yet but I know iostream.h provides a way to do it by typing
    flush keyword at the point where you want to emty the buffer.I am not clear about this but I think try to use

    cin>>var>>flush();

    or a similar one because some time ago I have a situation like this

    cin>>var1;
    cin.getline(var2);

    but this code does not work correctly unless you empty the previous '\n' character from buffer!!!

  4. #4
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Originally posted by golfinguy4
    Well, you could make it a win32 app and receive char messages.

    Why would you want to do this?
    I dunno Windows programming, but I think that I "know" dos programming.

    It's for a dos based (or win32 console) text editor that I've been playing with for months.

    nag, I don't what the user the have to hit the enter key at all. I wrote a simple keyboard driver using inline asm, but it works only with my 16 bit compilers. The function call locks up all of my 32 bit compilers. It must be my use of registers, but I dunno 32 bit asm either.

    Anywas, thanks for the feedback.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  5. #5
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>I know iostream.h provides a way to do it by typing
    flush keyword at the point where you want to emty the buffer.
    First, you can't use flush on an istream, second, flushing the stream doesn't give you unbuffered input, it just flushes the buffer after every character.

    >>Have any of you gurus come up with a method of obtaining unbuffered input in C++ using iostream.h alone?
    You can't do it unless your operating system has a feature to switch from cooked to raw terminal input. But there's no way using just C++ to get unbuffered input, it's too platform dependent.
    *Cela*

  6. #6
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    how about the old .......... getch().............function from

    conio.h library....????????/

  7. #7
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361

  8. #8
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Registers?

    It must be my use of registers
    Do you mean hardware registers? Because any windows OS "beyond" Win98 doesn't allow user mode programs access to the hardware. And, assembly won't help that either.

  9. #9
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    >Do you mean hardware registers? Because any windows >OS "beyond" Win98 doesn't allow user mode programs access >to the hardware. And, assembly won't help that either

    Really?? You mean to say that on my XP computer, if I throw in some inline assembly that references EAX or something, it will have a problem? Not that I really care, but...

    How will they continue to teach assembly in the schools?
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 04:13 PM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  3. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM