printing to cout while blocking for getch()?

This is a discussion on printing to cout while blocking for getch()? within the C++ Programming forums, part of the General Programming Boards category; I am attempting to make a simple telnet-like program in c++. What I need to know is: Is there a ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    9

    printing to cout while blocking for getch()?

    I am attempting to make a simple telnet-like program in c++. What I need to know is: Is there a way to print out text coming from recv() over a socket while waiting for getch() to return?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,437
    Yes, there is a way.
    But you're going to have to say which OS and compiler.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    9
    WinXP using Dev-c++

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Try
    Code:
    if(kbhit()) getch();
    else no_key_in_the_buffer();
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    9
    thank you, that worked exactly as i needed it too. the last problem now is, is there a way to peek into the recieve buffer for my blocking socket to see if a message is in the buffer without having to call and wait for recv()?

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by frozt
    thank you, that worked exactly as i needed it too. the last problem now is, is there a way to peek into the recieve buffer for my blocking socket to see if a message is in the buffer without having to call and wait for recv()?
    Yes, you can use the ioctrlsocket function to check how much data is waiting to be recieved.

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    9
    i can't find ioctrlsocket anywhere in msdn or google. could you post an example of how to use this?

  8. #8
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Instead, search

    ioctlsocket

  9. #9
    Registered User
    Join Date
    Jan 2006
    Posts
    9
    thanks for the help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "Spying" on cout
    By sirjis in forum C++ Programming
    Replies: 4
    Last Post: 11-06-2006, 04:00 PM
  2. cout to printf problems
    By hallo007 in forum C++ Programming
    Replies: 9
    Last Post: 09-27-2006, 10:22 AM
  3. Problem with cout
    By kristentx in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2006, 12:37 PM
  4. printf vs cout
    By RyeDunn in forum C++ Programming
    Replies: 5
    Last Post: 07-09-2002, 04:26 PM
  5. FAQ cout
    By evilmonkey in forum FAQ Board
    Replies: 1
    Last Post: 10-07-2001, 11:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21