|
-
June 7th, 2002, 03:07 PM
#1
unable to recognise 'space' char in ifstream
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
-
June 7th, 2002, 04:09 PM
#2
>> 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 >>
-
June 8th, 2002, 06:12 AM
#3
yeah.... it makes sense....
thx a lot!
-
June 8th, 2002, 04:09 PM
#4
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.
-
June 9th, 2002, 03:24 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|