Click to See Complete Forum and Search --> : OS inconsistancies?
Energon
06-19-2001, 07:42 PM
I'm still working on my little portable chat app... but I've run into a bit of a stump... when a user sends a message, I want them to be able to enter a whole line of text, including spaces... so I figured I'd get by with something like this:
string message;
getline(cin, message);
Simple enough... but the problem is that it works fine in Linux, but in Windows, the user has to hit Return twice and I have no idea why... this can't be the only time this has happened to somebody, so what's the general work-around for it?
lsibn
06-19-2001, 10:22 PM
I do not know how to fix this, but I suspect your problem lies with the Win32 implementation of cin or getline.
In win32, getline waits for return before accepting input. So does cin. Therefore, cin gets the first return (probably) and the second one goes to getline.
In linux, I would suspect that cin doesn't require enter to proceed, but I could be wrong...
Energon
06-20-2001, 12:10 AM
well poop... I 'spose the only good away around this is to use cin.getline() and a C-style string... *grumbles*
sans-hubris
06-20-2001, 02:06 AM
It's a bug in Microsoft's implementation of the STL getline function, it has nothing to do with what you're doing. There is a fix: http://support.microsoft.com/support/kb/articles/Q240/0/15.ASP
:cool:
Energon
06-20-2001, 09:55 AM
Why haven't they put this on a service pack? It seems like a big enough concern to fix...
lsibn
06-20-2001, 10:24 AM
Originally posted by ndogg.cpp:
<STRONG>It's a bug in Microsoft's implementation of the STL getline function, it has nothing to do with what you're doing. There is a fix: http://support.microsoft.com/support/kb/articles/Q240/0/15.ASP
:cool:</STRONG>
What? A bug that clearly adversely affects performance on a Microsoft system? I don't believe you. I think you posted that link just so people would take your word for it and not look it up.
:cool:
sans-hubris
06-20-2001, 08:31 PM
Originally posted by Energon:
<STRONG>Why haven't they put this on a service pack? It seems like a big enough concern to fix...</STRONG>Why? What would the point be for such a simple fix? Wait a sec, you were being sarcastic, right?
Energon
06-21-2001, 10:18 AM
Okay... so I do the change, and I switch my code over to use getline(), but now, it doesn't even let the user input... it just takes emptiness, puts it in my string and calls it good... I tried calling cin.clear() before getline() just to see if I set a bit on it wrong or something, but that ain't it...
and low and behold, it still works 100% in Linux... :rolleyes:
sans-hubris
06-21-2001, 10:21 PM
Originally posted by Energon:
<STRONG>Okay... so I do the change, and I switch my code over to use getline(), but now, it doesn't even let the user input... it just takes emptiness, puts it in my string and calls it good... I tried calling cin.clear() before getline() just to see if I set a bit on it wrong or something, but that ain't it...
and low and behold, it still works 100% in Linux... :rolleyes:</STRONG>
Try doing a cin.ignore(1000, '\n'), I dunno, it might work. I'm not exactly sure why you're having problems with it in VisC++, I didn't have too many with it. If your code is complient with the standard you really shouldn't have too many problems, even on a MS compiler.
No, wait, I forgot about Borland C++. I really hate Borland, almost as much as MS. Their compiler is definitely worse than VisC++. It has to be the lowest of the low of all compilers, I swear.
[ 21 June 2001: Message edited by: ndogg.cpp ]
Energon
06-21-2001, 11:17 PM
That did it... it turned the program into something like the Linux version... odd... so it takes a change to the stl string header, and then this? What did that last change do? The info I have isn't very clear on what exactly that did...
Energon
06-21-2001, 11:24 PM
grrr... it's still inconsistant... it seems like I'm going to have to use cin.ignore() before every getline() in one spot, but not in another...
why can't MS just make crap work when I need it? I'm about ready to just say screw it and use C style strings...
sans-hubris
06-22-2001, 12:10 AM
Originally posted by Energon:
<STRONG>grrr... it's still inconsistant... it seems like I'm going to have to use cin.ignore() before every getline() in one spot, but not in another...
why can't MS just make crap work when I need it? I'm about ready to just say screw it and use C style strings...</STRONG>I highly recommend that you use cstrings for only getlines and quickly assign them to STL strings.
Energon
06-22-2001, 01:17 AM
hmm... well... at least I have one more thing to add to the "why I hate developing for Windows" list... *shrug*
thanks for the help...
Energon
06-22-2001, 11:41 AM
a friend of mine pointed me to stlport (a diff. implementation of the stl api, but portable and based on the SGI code... it didn't need any changes to the string class, but it still doesn't wait for input in my code, but it does wait in a little test program I made... so I'm gonna have to fine comb my code and see what I did...