c++ - Possible reasons for tellg() failing? -


ifstream :: tellg () -13 for a fixed file is returning.

Actually, I've written a feature that analyzes some source code; I open all the files alphabetically, I start with "Apple CPP" and it works perfectly .. But when "conversion is .ptp", always on the same file, reading a line After successfully gives tellg (-13). / P>

The code in question is:

 for  (int i = 0; i   

ATOF is:

bool etf (if {mfile.tellg () <0) FATAL (format ("DEBUG - tellg ():% d")% mFile.tellg ()); If (mFile.tellg ()> = GetSize ()) return true; return false; }

After successfully reading the first row of Conversion.cpp, it is always DEBUG - tellg (): -13 .

This is the complete TextIFile class (written by me, may be the error):

  class textfile {public: textfile (string) And path): mPath (path), mSize (0) {mFile.open (path.c_str (), std :: ios :: in); If (! MFile.is_open ()) FATAL (format ("% s can not open:% s")% path.c_str ()% strerror (errno)); } Get the string GetPath () const {return mPath; } Size_t GetSize () {if mSize returns (mSize); Const size_t current_position = mFile.tellg (); MFile.seekg (0, std :: ios :: end); MSize = mFile.tellg (); MFile.seekg (CURRENT_POSITION); Return mSize; } Bool etf () {if (mFile.tellg ()}  gt; ; = GetSize (); return true; details are false;} string readline () {string ret; gateline (mfile, write); checkErrors (); return rit;} string readwall () {string write (std :: istreambuf_iterator & Lt; char & gt; (mFile), std :: istreambuf_iterator & lt; char & gt; (); CheckErrors (); Return Rit;} Private: Zero Checker () (if (! MFile.good ) FATAL (format "An error occurred while performing an I / O operation at% s")% mPath;} Const String mPath; First Mfile; Size_t mSize;};  

Em> Edit: I found the reason: Line end conversion and both \ r \ n instead of both \ r \ n, I saved them with \ r \ n and it worked. Is not going to happen?

It is difficult to know what exactly is Conversion.cpp . However, with the stream posts & lt; is not defined by the standard. Before you format it, you might want to consider the perfect integer type of a full artist; I do not know how to format FATAL and format () or how the % operator is overloaded. Stream positions do not need to map to an integer in an anticipated way, of course if the file does not open in binary mode.

You may want to consider an alternative implementation for AtEof () . Say something:

  bool etf () {return mFile.peek () == ifstream :: traits_type :: eof (); }  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -