Click to See Complete Forum and Search --> : getline(istream, string) kookiness
tecknophreak
01-13-2005, 05:28 PM
I have a file with lines similar to:
0x123
0x234
flag
0x123
When I read the input using getline(istream, string) and don't convert the file to unix, the string for lines looking like 0x123 are fine, but the line like flag gives string a ^M at the end of the string. Yeah, \r, but why only for lines of a char string type as opposed to lines of an ascii representation of an hex number?
Of course the easy way around that would be removing the ^M if it is there, which is what I'm doing, but I'm just curious why its only there in that case.
bwkaz
01-13-2005, 07:59 PM
Open the file with a hex editor. Maybe the hex-number lines never had a \r written to them for some reason?
Or maybe getline(whatever) is treating \r as whitespace when it reads in the hex-number lines for some reason? Are you reading them all into strings, or are you reading the hex-numbers into integers?
tecknophreak
01-13-2005, 09:57 PM
Originally posted by bwkaz
Open the file with a hex editor. Maybe the hex-number lines never had a \r written to them for some reason?
Already done, all lines have the same \r\n, since it was a file created by a Windows program.
Or maybe getline(whatever) is treating \r as whitespace when it reads in the hex-number lines for some reason?
I'm guessing this is what it's doing, I'm just curious if any knows why or has ever seen this before.
Are you reading them all into strings, or are you reading the hex-numbers into integers?
They're both getting read into strings, since my program never needs to actually know the number itself and it gets treated as a string.
bwkaz
01-14-2005, 08:39 PM
Hmm... If you're always reading into strings, then (AFAIK) it should always treat the same characters as whitespace. Unless -- does getline take a length parameter? Might the line in question be one character longer than the length, maybe?
If it's not that, I'm stumped...
tecknophreak
01-17-2005, 12:53 AM
AFAIK, even if it uses the same default length as is.getline(char *), which is (i think) 80, my lines are well short of that.
So I guess you're as stumped as I am. :eek: