Thread: cin.getline and msgrcv

  1. #1
    Registered User
    Join Date
    May 2004

    cin.getline and msgrcv

    I posted this on the Linuxprogramming, but I thought id post it here since its C++ as well.

    Anyways, Im working on this little chat program and the other programs should be able to communicate with each other, the only problem is with my cin.getline, i use that to enter in text, but it blocks, so it waits for the user to enter something in and then itll receive, even if the other user sent it before hand. my code is posted at the site below. Is there a way to check if cin.getline is true or false, i used an if statement but it didnt help, apparently cin.getline return *this, instead of 1 or 0. But here's my code, hope someone can help. Thanks!

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Seattle, WA
    Please do not post the same thing in more than one forum.

    That said, this sounds like something that would be difficult to do in the console. You might want to look at this page from the faq.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Basically, you need to use whatever the OS gives you to read a character at a time, along with the ability to poll for input (if that is what you are doing).

    When you've received a whole line, then you convert it to a C++ string and then you're back into normal C++ land.

    But it's up to you to construct the bridge between them.

    Your xpost is in the trash.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed