From bug-request at octave dot org Thu Dec 16 13:55:32 2004 Subject: RE: Possible Error in -ascii save/restore From: "John W. Eaton" To: "John W. Eaton" Cc: , Date: Thu, 16 Dec 2004 14:56:33 -0500 On 16-Dec-2004, I wrote: | Note the is.tellg() and is.seekg(). I think this is failing when the | filesystem is mounted in text mode because then there is some | translation going on for CRLF pairs. Is this a bug in Octave or the | way the Cygwin text mode filesystem works? All we want Octave to do | here is return to the previous location in the file and read again. Try the following program on a Cygwin filesystem mounted in textmode. When I compile this program with g++ 3.3.x, it prints line 1 line 2 pos = 18 line 3 ne 3 instead of the expected line 1 line 2 pos = 14 line 3 line 3 (or perhaps line 1 line 2 pos = 16 line 3 line 3 if the pointer is also counting the CR characters in the input). Will someone please verify this and report the problem as a bug to the Cygwin or libstdc++ maintainers (whichever is more appropriate, or both)? Thanks, jwe #include #include static void read_a_line (std::istream& is) { char c; while (is.get (c)) { std::cerr << c; if (c == '\n') break; } } int main (void) { std::ofstream ofoo ("foo.txt"); ofoo << "line 1\nline 2\nline 3\nline 4\n"; ofoo.close (); std::ifstream ifoo ("foo.txt"); // Read the first two lines, including the newlines, echoing them to // std::cerr. read_a_line (ifoo); read_a_line (ifoo); // Mark our position. std::streampos pos = ifoo.tellg (); // Where are we? I would expect 7 characters per line, so we should // be at 14. std::cerr << "pos = " << pos << std::endl; // Read and echo another line. read_a_line (ifoo); // Go back to the saved position then read and echo again. ifoo.seekg (pos); read_a_line (ifoo); ifoo.close (); return 0; } ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------