Click to See Complete Forum and Search --> : unable to recognise 'space' char in ifstream
boccio
June 7th, 2002, 03:07 PM
hi,
I'm stuck with a quite stupid problem....
I'm trying to parse a txt file, and seems like I cannot recognise 'space' ( asc(32) char) .... concider this:
ifstream input("some_text.txt");
while (input >> * pszFile)
{
// ....
if (* pszFile == 32) // space char
// do smth...
all other chars are recognised correctly, only 'space' not.
what am I doing wrong??
thx for reading
JMS
June 7th, 2002, 04:09 PM
>> what am I doing wrong..
what your doing wrong is using the >> operator to extract your characters. Using this it seemed to skip spaces. I'm not sure if this is a bug or a feature. But to get the results you need use a different method for sucking out the characters...
Here is code which worked for me..
char szFile = ' ';
int i = 0;
ifstream input("\\foo.txt", ios::binary);
while ( input.get(szFile) )
{
i++;
}
you could probable loose the ios::binary.... just put that in when I was experimenting with >>
boccio
June 8th, 2002, 06:12 AM
yeah.... it makes sense....
thx a lot!
Bob Davis
June 8th, 2002, 04:09 PM
The reason that the extraction operator >> does not return the ' ' character is that it is a delimiter for tokenizing the contents of the stream. It does not return the delimiters, and I'm not sure whether you can make it include them or not. I know you can do something like a
cin >> noskipws;
I'm not sure what this does, it's been a while since I've used it, but you may want to look it up in your C++ reference of choice.
boccio
June 9th, 2002, 03:24 AM
thx for ********ing.....
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.