ftell?

Started by
4 comments, last by Javelin 20 years, 8 months ago
Hi! How can it be that ifstream::ftell() alters the read position?! I''m using VC++ and ifstream not std::ifstream. while(...) { infile.ftell(); infile.getline(buffer,200); // Process buffer data } is NOT the same as while(...) { infile.getline(buffer,200); // Process buffer data } The thing is that getline() reads one byte too much somtimes if ftell is there. Any thoughts?
// Javelin// Assumption is the mother of all fuckups...
Advertisement
quote:Original post by Javelin
How can it be that ifstream::ftell() alters the read position?!
I''m using VC++ and ifstream not std::ifstream.


Eh?! i don''t know what you mean by "ifstream not std::ifstream".

and ifstream has no ftell. there is a tellg(), however...

yes sorry... meant tellg()

I''m not using the ifstream in namespace std.



// Javelin
-- Why do something today when you can do it tomorrow... --
// Javelin// Assumption is the mother of all fuckups...
quote:Original post by Javelin
I''m not using the ifstream in namespace std.


Then nobody can help you.

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
hmmz... well

I think most ppl using MSVC++ do not use the std:: version of the streams... If you want to use the std:: versions you have to type it explicit.
E.g.
std::ifstream infile;
using namespace std;
or
using std::ofstream;


I worked around the problem by using a binary reading of the file instead, but that''s not a very neat solution though.

I do not know if it''s a bug in the MSVC++ libraries... but the ifstream::tellg() actually alters the reading position in the file.

// Javelin
-- Why do something today when you can do it tomorrow... --
// Javelin// Assumption is the mother of all fuckups...
I think most ppl using MSVC++ do not use the std:: version of the streams... If you want to use the std:: versions you have to type it explicit.

Then most people using MSVC++ learned C++ improperly. <iostream.h> and <fstream.h> are not standard C++ library headers.

I do not know if it''s a bug in the MSVC++ libraries... but the ifstream::tellg() actually alters the reading position in the file.

Since the ifstream class that is not in the std namespace is old and non-standard there is absolutely no telling what the problem might be. Since there is no specification for what ifstream::tellg should do, ifstream::tellg could do just about anything, including modifying the get pointer''s position.

Which is why people should use standard C++ classes, like std::ifstream

Additionally - MSVC6''s library is buggy, see link in sig.

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement