More tests for streams.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2910 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 1999-06-27 16:42:54 +00:00
parent f776e250d9
commit e57e26dd03
2 changed files with 68 additions and 6 deletions

View File

@ -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

View File

@ -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');