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:
@@ -106,11 +106,11 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
|
|||||||
textCtrl.Clear();
|
textCtrl.Clear();
|
||||||
textCtrl << "\nTest fstream vs. wxFileStream:\n\n";
|
textCtrl << "\nTest fstream vs. wxFileStream:\n\n";
|
||||||
|
|
||||||
|
textCtrl.WriteText( "Writing to ofstream and wxFileOutputStream:\n" );
|
||||||
|
|
||||||
ofstream std_file_output( "test_std.dat" );
|
ofstream std_file_output( "test_std.dat" );
|
||||||
wxFileOutputStream file_output( "test_wx.dat" );
|
wxFileOutputStream file_output( "test_wx.dat" );
|
||||||
|
|
||||||
textCtrl.WriteText( "Writig to fstream:\n" );
|
|
||||||
|
|
||||||
wxString tmp;
|
wxString tmp;
|
||||||
signed int si = 0xFFFFFFFF;
|
signed int si = 0xFFFFFFFF;
|
||||||
tmp.Printf( "Signed int: %d\n", si );
|
tmp.Printf( "Signed int: %d\n", si );
|
||||||
@@ -130,12 +130,65 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
|
|||||||
file_output << d << "\n";
|
file_output << d << "\n";
|
||||||
std_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!" );
|
wxString str( "Hello!" );
|
||||||
tmp.Printf( "String: %s\n", str.c_str() );
|
tmp.Printf( "String: %s\n", str.c_str() );
|
||||||
textCtrl.WriteText( tmp );
|
textCtrl.WriteText( tmp );
|
||||||
file_output << str << "\n";
|
file_output << str << "\n";
|
||||||
std_file_output << str.c_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
|
#if wxUSE_UNICODE
|
||||||
|
@@ -284,6 +284,7 @@ char wxStreamBuffer::GetChar()
|
|||||||
}
|
}
|
||||||
|
|
||||||
GetFromBuffer(&c, 1);
|
GetFromBuffer(&c, 1);
|
||||||
|
|
||||||
m_stream->m_lastcount = 1;
|
m_stream->m_lastcount = 1;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@@ -624,7 +625,7 @@ wxInputStream& wxInputStream::operator>>(signed int& i)
|
|||||||
wxInputStream& wxInputStream::operator>>(signed long& i)
|
wxInputStream& wxInputStream::operator>>(signed long& i)
|
||||||
{
|
{
|
||||||
/* I only implemented a simple integer parser */
|
/* I only implemented a simple integer parser */
|
||||||
char c;
|
int c;
|
||||||
int sign;
|
int sign;
|
||||||
|
|
||||||
while (isspace( c = GetC() ) )
|
while (isspace( c = GetC() ) )
|
||||||
@@ -639,8 +640,12 @@ wxInputStream& wxInputStream::operator>>(signed long& i)
|
|||||||
if (c == '-') {
|
if (c == '-') {
|
||||||
sign = -1;
|
sign = -1;
|
||||||
c = GetC();
|
c = GetC();
|
||||||
} else
|
} else if (c == '+') {
|
||||||
sign = 1;
|
sign = 1;
|
||||||
|
c = GetC();
|
||||||
|
} else {
|
||||||
|
sign = 1;
|
||||||
|
}
|
||||||
|
|
||||||
while (isdigit(c)) {
|
while (isdigit(c)) {
|
||||||
i = i*10 + c;
|
i = i*10 + c;
|
||||||
@@ -673,7 +678,7 @@ wxInputStream& wxInputStream::operator>>(unsigned int& i)
|
|||||||
wxInputStream& wxInputStream::operator>>(unsigned long& i)
|
wxInputStream& wxInputStream::operator>>(unsigned long& i)
|
||||||
{
|
{
|
||||||
/* I only implemented a simple integer parser */
|
/* I only implemented a simple integer parser */
|
||||||
char c;
|
int c;
|
||||||
|
|
||||||
while (isspace( c = GetC() ) )
|
while (isspace( c = GetC() ) )
|
||||||
/* Do nothing */ ;
|
/* Do nothing */ ;
|
||||||
@@ -709,8 +714,12 @@ wxInputStream& wxInputStream::operator>>(double& f)
|
|||||||
if (c == '-') {
|
if (c == '-') {
|
||||||
sign = -1;
|
sign = -1;
|
||||||
c = GetC();
|
c = GetC();
|
||||||
} else
|
} else if (c == '+') {
|
||||||
sign = 1;
|
sign = 1;
|
||||||
|
c = GetC();
|
||||||
|
} else {
|
||||||
|
sign = 1;
|
||||||
|
}
|
||||||
|
|
||||||
while (isdigit(c)) {
|
while (isdigit(c)) {
|
||||||
f = f*10 + (c - '0');
|
f = f*10 + (c - '0');
|
||||||
|
Reference in New Issue
Block a user