The gcc -v output is at the bottom of this. The following small testcase produces incorrect file output as far back as gcc 3.2 <mingw special 20020817-1>. Gcc 3.2 included in Mandrake Linux 9.1 produced the expected output in the file. The following code is compiled on WinXP Pro using: g++ -mno-cygwin database.cpp -odatabase //database.cpp #include <fstream> #include <iostream> using std::ios; typedef unsigned short u_short; bool NumberAlreadyExists ( std::fstream &rRead, u_short number ) { bool exist = false; u_short temp_number; rRead.seekg( 0 ); //go to start of file while ( rRead >> temp_number ) { if ( temp_number == number ) exist = true; } if ( rRead.eof() ) { rRead.clear(); rRead.seekg(0); //go to beginning } return exist; } int main( ) { std::fstream data ("data.txt",ios::in|ios::out|ios::trunc); if (!data) return 1; u_short four_digit_number; char continue_loop = 'y'; while ( continue_loop == 'y' ) { std::cout <<"Enter a positive 4 digit number: "; std::cin >> four_digit_number; if ( NumberAlreadyExists ( data, four_digit_number ) ) { std::cout << "\aNumber Already Exists!!\n"; continue; } data.seekp (0, std::ios::end ); // go to end of file data << four_digit_number << std::endl; std::cout << "Continue ...?(y/n): "; std::cin>>continue_loop; } data.close(); return 0; } /* Output: Enter a positive 4 digit number: 1000 Continue ...?(y/n): y Enter a positive 4 digit number: 1001 Continue ...?(y/n): n Contents of data.txt: 11000 1001 */ Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/specs Configured with: /GCC/gcc-3.3.1-3/configure --with-gcc --with-gnu-ld --with-gnu- as --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexe cdir=/usr/sbin --mandir=/usr/share/man --infodir=/usr/share/info --enable-langua ges=c,ada,c++,f77,pascal,java,objc --enable-libgcj --enable-threads=posix --with -system-zlib --enable-nls --without-included-gettext --enable-interpreter --enab le-sjlj-exceptions --disable-version-specific-runtime-libs --enable-shared --dis able-win32-registry --enable-java-gc=boehm --disable-hash-synchronization --verb ose --target=i686-pc-cygwin --host=i686-pc-cygwin --build=i686-pc-cygwin Thread model: posix gcc version 3.3.1 (cygming special)
Can you try a newer compiler, the compiler which you are using is a prelease from your vender (cygwin)? Can you also next time report it first to cygwin as this could be a bug in cygwin's runtime. (or mingw if you are using that)?
This is a dup of bug 13333. *** This bug has been marked as a duplicate of 13333 ***