>In .Net 2003 if a line, read from a text file is larger
than a size parameter, the ifstream getline(buff, sze) put
the file pointer to the EOF, so next peek() returns EOF.
I saw this problem also when size was 2000 but line was
1200 bytes long.
There is no such problem with .Net 2002
The same function in .Net 2002 works fine.
Dave,
Do you have a simple example (and a simple file that illustrates the
difference)?
I think I can reproduce what you're seeing, but I get consistent
results with VS2003 & VC6 (I don't have VS2002 installed to check what
it does).
Here's the code I've tried if you want to check how this behaves for
you with VS2002 & VS2003:
#include <string>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream is;
is.open( argv[1], ios_base::in );
char buffer[10];
is.getline( buffer, 5 );
int ret = is.peek();
if ( char_traits<char>::eof() == ret )
{
cout << "EOF returned";
}
else
{
cout << "Not EOF";
}
is.close();
return 0;
}
and the sample file is a text file containing:
12345678901234567890
987654321
After calling getline, the buffer contains "1234" (and a null
character), and the following call to peek always (it seems incorrect
to me) returns eof.
Stepping through the code, it appears that peek fails because the
getline method sets the state of the stream to a failure case because
the buffer end is reached. Skipping past this check does return the
next character in the file, so the file pointer would appear to be
correct.
I don't usually use with these stream methods, so I'm not sure what
the expected behaviour should be.
Dave Lowndes
--
MVP VC++ FAQ:
http://www.mvps.org/vcfaq