From bug-request at octave dot org Fri Dec 17 07:24:10 2004 Subject: RE: Possible Error in -ascii save/restore From: To: Cc: Date: Fri, 17 Dec 2004 04:19:07 -0600 Hello John, I am no C++ programmer, but I did the following (after copying your source code to a file test.cc) HPA007 at now2032 ~ $ g++ test.cc -o TEST HPA007 at now2032 ~ $ ./TEST.exe line 1 line 2 pos = 18 line 3 ne 3 HPA007 at now2032 ~ I.e. the same as you get. Regards, Hallvard -----Original Message----- From: John W. Eaton [mailto:jwe at bevo dot che dot wisc dot edu] Sent: 16. desember 2004 20:57 To: John W. Eaton Cc: Paulsen, Hallvard; bug at octave dot org Subject: RE: Possible Error in -ascii save/restore 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 -------------------------------------------------------------