Archived

This topic is now archived and is closed to further replies.

Javelin

ftell?

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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...

Share this post


Link to post
Share on other sites
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 ]

Share this post


Link to post
Share on other sites
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... --

Share this post


Link to post
Share on other sites
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 ]

Share this post


Link to post
Share on other sites