From: Robert Roebling Date: Sun, 27 Jun 1999 16:42:54 +0000 (+0000) Subject: More tests for streams. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/e57e26dd03d65ccb816d34b5254398b448e74018 More tests for streams. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2910 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/typetest/typetest.cpp b/samples/typetest/typetest.cpp index 1cd285b13b..0df7ed9d34 100644 --- a/samples/typetest/typetest.cpp +++ b/samples/typetest/typetest.cpp @@ -106,11 +106,11 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event)) textCtrl.Clear(); textCtrl << "\nTest fstream vs. wxFileStream:\n\n"; + textCtrl.WriteText( "Writing to ofstream and wxFileOutputStream:\n" ); + ofstream std_file_output( "test_std.dat" ); wxFileOutputStream file_output( "test_wx.dat" ); - textCtrl.WriteText( "Writig to fstream:\n" ); - wxString tmp; signed int si = 0xFFFFFFFF; tmp.Printf( "Signed int: %d\n", si ); @@ -130,12 +130,65 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event)) file_output << d << "\n"; std_file_output << d << "\n"; + float f = 0.00001; + tmp.Printf( "Float: %f\n", f ); + textCtrl.WriteText( tmp ); + file_output << f << "\n"; + std_file_output << f << "\n"; + wxString str( "Hello!" ); tmp.Printf( "String: %s\n", str.c_str() ); textCtrl.WriteText( tmp ); file_output << str << "\n"; std_file_output << str.c_str() << "\n"; + textCtrl.WriteText( "\nReading from ifstream:\n" ); + + ifstream std_file_input( "test_std.dat" ); + + std_file_input >> si; + tmp.Printf( "Signed int: %d\n", si ); + textCtrl.WriteText( tmp ); + + std_file_input >> ui; + tmp.Printf( "Unsigned int: %u\n", ui ); + textCtrl.WriteText( tmp ); + + std_file_input >> d; + tmp.Printf( "Double: %f\n", d ); + textCtrl.WriteText( tmp ); + + std_file_input >> f; + tmp.Printf( "Float: %f\n", f ); + textCtrl.WriteText( tmp ); + + std_file_input >> str; + tmp.Printf( "String: %s\n", str.c_str() ); + textCtrl.WriteText( tmp ); + + textCtrl.WriteText( "\nReading from wxFileInputStream:\n" ); + + wxFileInputStream file_input( "test_wx.dat" ); + + file_input >> si; + tmp.Printf( "Signed int: %d\n", si ); + textCtrl.WriteText( tmp ); + + file_input >> ui; + tmp.Printf( "Unsigned int: %u\n", ui ); + textCtrl.WriteText( tmp ); + + file_input >> d; + tmp.Printf( "Double: %f\n", d ); + textCtrl.WriteText( tmp ); + + file_input >> f; + tmp.Printf( "Float: %f\n", f ); + textCtrl.WriteText( tmp ); + + file_input >> str; + tmp.Printf( "String: %s\n", str.c_str() ); + textCtrl.WriteText( tmp ); } #if wxUSE_UNICODE diff --git a/src/common/stream.cpp b/src/common/stream.cpp index b054abb9f7..7d0e543fdb 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -284,6 +284,7 @@ char wxStreamBuffer::GetChar() } GetFromBuffer(&c, 1); + m_stream->m_lastcount = 1; return c; } @@ -624,7 +625,7 @@ wxInputStream& wxInputStream::operator>>(signed int& i) wxInputStream& wxInputStream::operator>>(signed long& i) { /* I only implemented a simple integer parser */ - char c; + int c; int sign; while (isspace( c = GetC() ) ) @@ -639,8 +640,12 @@ wxInputStream& wxInputStream::operator>>(signed long& i) if (c == '-') { sign = -1; c = GetC(); - } else + } else if (c == '+') { sign = 1; + c = GetC(); + } else { + sign = 1; + } while (isdigit(c)) { i = i*10 + c; @@ -673,7 +678,7 @@ wxInputStream& wxInputStream::operator>>(unsigned int& i) wxInputStream& wxInputStream::operator>>(unsigned long& i) { /* I only implemented a simple integer parser */ - char c; + int c; while (isspace( c = GetC() ) ) /* Do nothing */ ; @@ -709,8 +714,12 @@ wxInputStream& wxInputStream::operator>>(double& f) if (c == '-') { sign = -1; c = GetC(); - } else + } else if (c == '+') { sign = 1; + c = GetC(); + } else { + sign = 1; + } while (isdigit(c)) { f = f*10 + (c - '0');