From: <no...@so...> - 2001-10-25 01:33:02
|
Bugs item #474450, was opened at 2001-10-24 05:30 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=102435&aid=474450&group_id=2435 Category: gcc Group: None Status: Open Resolution: None Priority: 5 Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: ostrstream.str() problem in Windows xl Initial Comment: I have to deal with a binary file from an outside source that I need to tweak for my purposes. In the program below, I'm converting an integer to formatted output to a string, copying the string to another and outputting the result. In Windows NT the program produces the output below: ***********************PROGRAM******************** C:>type iostreamX.cpp #include <iostream> #include <fstream> #include <strstream> #include <string> #include <iomanip> using namespace std; int main(){ int i=123; cout.width(5); cout.fill('0'); cout << i << endl; ostrstream ost; ost.width(5); ost.fill('0'); ost << i; cout << ost.str() << endl; string mystring="xxxxxxxxxxxxxxxxxxxxxxxx"; cout << mystring << endl; mystring.replace(3,5,ost.str(),0,5); cout << mystring << endl; mystring.replace(12,1,ost.str(),0,5); cout << mystring << endl; ofstream out("test.txt",ios::out|ios::bin); out << ost.str(); out.write((char*) &i, sizeof(i)); out.close(); return 0; } C:>g++ iostreamx.cpp ***********************OUTPUT******************** C:>a 00123 00123 xxxxxxxxxxxxxxxxxxxxxxxx xxx00123xxxxxxxxxxxxxxxx xxx00123xxxx00123xxxxxxxxxxx ************************************************* ************************************************* IN WINDOWS XL, THE OUTPUT IS 00123 00123[04][61] xxxxxxxxxxxxxxxxxxxxxxxx xxx00123xxxxxxxxxxxxxxxx xxx00123xxxx00123xxxxxxxxxxx WHERE THE [04][61] IN THE SECOND LINE STANDS FOR TWO EXTRA BYTES CONTAINING ASCII CHARACTERS 4 AND 61 DECIMAL. APPARENTLY IN WINDOWS XL, MINGW DOESN'T KNOW HOW LONG THE STRING IS, WHILE IN NT IT DOES. AS AN UNRECONSTRUCTED FORTRAN PROGRAMMER, I FREQUENTLY FUMBLE WITH THE SIMPLEST MECHAINCS OF C++ PROGRAMMING, BUT I DON'T THINK IT'S ME THIS TIME. OF COURSE, THE SAME THINGS CAN BE ACCOMPLISHED WITH MEMMOVE AND C INPUT/OUTPUT AND I HAVE A VERSION LIKE THAT WHICH WORKS IN BOTH NT AND XL. (FOR THAT MATTER, I HAVE A VERSION IN FORTRAN THAT WORKS IN NT AND XL WITH THE g77 COMPILER.) Tom Messenger ---------------------------------------------------------------------- >Comment By: Danny Smith (dannysmith) Date: 2001-10-24 18:33 Message: Logged In: YES user_id=11494 I don't have XP so I can't test, but this looks very similar to some fseek problems on W9x. Would you be willing to try a rebuild of libstdc++.a to test if that is the case? BTW what does GetVersionEx return in dwPlatformId field of OSVERSIONINFO for Windows XP Danny ---------------------------------------------------------------------- Comment By: Nobody/Anonymous (nobody) Date: 2001-10-24 10:46 Message: Logged In: NO OOPS! I meant WINDOWS XP throughout, of course. Tom Messenger ---------------------------------------------------------------------- You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=102435&aid=474450&group_id=2435 |