Mail Archives: djgpp/2001/09/16/07:03:24
From: | Alex Vinokur <alexvn AT bigfoot DOT com>
|
Newsgroups: | comp.os.msdos.djgpp,comp.lang.c++
|
Subject: | whitespaces & strstream
|
Followup-To: | comp.lang.c++
|
Date: | Sun, 16 Sep 2001 13:49:07 +0200
|
Organization: | Scopus Network Technologies
|
Lines: | 180
|
Message-ID: | <3BA491B2.E977E1A1@bigfoot.com>
|
NNTP-Posting-Host: | gateway.scopus.co.il (194.90.203.161)
|
Mime-Version: | 1.0
|
X-Trace: | fu-berlin.de 1000637384 10847816 194.90.203.161 (16 [79865])
|
X-Mailer: | Mozilla 4.7 [en] (Win98; I)
|
X-Accept-Language: | en
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
=========================================================
GNU C++ version 2.95.3 20010315/djgpp (release) (djgpp)
compiled by GNU C version 2.95.3 20010315/djgpp (release)
Windows98
=========================================================
Here is a program, results of the running and several questions.
###### Source file ######
#include <string>
#include <strstream>
//-------------------------------------
int main ()
{
string init_str,
from1,
to1,
from2,
to2,
from3,
to3,
from4,
to4;
strstream tmp_ss1,
tmp_ss2,
tmp_ss3,
tmp_ss4;
bool rc_bool;
init_str = " ";
//-------------------------
cout << endl;
cout << " === Test#1 ===" << endl;
from1 = init_str;
tmp_ss1.setf (ios::skipws);
tmp_ss1 << from1;
tmp_ss1 << ends;
to1 = tmp_ss1.str();
cout << "tmp_ss1 : in_avail = "
<< tmp_ss1.rdbuf()->in_avail()
<< from1
<< endl;
tmp_ss1.rdbuf()->freeze (0);
cout << "from1 = <" << from1 << ">" << endl;
cout << "to1 = <" << to1 << ">" << endl;
cout << ((from1 == to1) ? "OK : from1 == to1" : "FAILURE : from1 !=
to1") << endl;
//-------------------------
cout << endl;
cout << " === Test#2 ===" << endl;
from2 = init_str;
tmp_ss2.unsetf (ios::skipws);
tmp_ss2 << from2;
tmp_ss2 << ends;
to2 = tmp_ss2.str();
cout << "tmp_ss2 : in_avail = "
<< tmp_ss2.rdbuf()->in_avail()
<< from2
<< endl;
tmp_ss2.rdbuf()->freeze (0);
cout << "from2 = <" << from2 << ">" << endl;
cout << "to2 = <" << to2 << ">" << endl;
cout << ((from2 == to2) ? "OK : from2 == to2" : "FAILURE : from2 !=
to2") << endl;
//-------------------------
cout << endl;
cout << " === Test#3 ===" << endl;
from3 = init_str;
tmp_ss3.setf (ios::skipws);
tmp_ss3 << from3;
tmp_ss3 << ends;
rc_bool = (tmp_ss3 >> to3);
cout << "tmp_ss3 : in_avail = "
<< tmp_ss3.rdbuf()->in_avail()
<< from3
<< endl;
tmp_ss3.rdbuf()->freeze (0);
cout << "from3 = <" << from3 << ">" << endl;
if (rc_bool) cout << "to3 = <" << to3 << ">" << endl;
else cout << "to3 : Cannot get" << endl;
cout << ((from3 == to3) ? "OK : from3 == to3" : "FAILURE : from3 !=
to3") << endl;
//-------------------------
cout << endl;
cout << " === Test#4 ===" << endl;
from4 = init_str;
tmp_ss4.unsetf (ios::skipws);
tmp_ss4 << from4;
tmp_ss4 << ends;
rc_bool = (tmp_ss4 >> to4);
cout << "tmp_ss4 : in_avail = "
<< tmp_ss4.rdbuf()->in_avail()
<< from4
<< endl;
tmp_ss4.rdbuf()->freeze (0);
cout << "from4 = <" << from4 << ">" << endl;
if (rc_bool) cout << "to4 = <" << to4 << ">" << endl;
else cout << "to4 : Cannot get" << endl;
cout << ((from4 == to4) ? "OK : from4 == to4" : "FAILURE : from4 !=
to4") << endl;
return 4;
}
#########################
######## Running ########
=== Test#1 ===
tmp_ss1 : in_avail = 1
from1 = < >
to1 = < >
OK : from1 == to1
=== Test#2 ===
tmp_ss2 : in_avail = 1
from2 = < >
to2 = < >
OK : from2 == to2
=== Test#3 ===
tmp_ss3 : in_avail = 0
from3 = < >
to3 = < >
FAILURE : from3 != to3
=== Test#4 ===
tmp_ss4 : in_avail = 1
from4 = < >
to4 : Cannot get
FAILURE : from4 != to4
#########################
Questions.
#1. Test#1 contains tmp_ss1.setf (ios::skipws).
Test#2 contains tmp_ss2.unsetf (ios::skipws).
In spite of that both test#1 and test#2
produce the same OK-result.
Why?
#2. Both test#3 and test#4 produce FAILURE-result.
Why?
Can we get OK-result using the clause
tmp_ss >> to; [ NOT : to = tmp_ss.str(); ] ?
===========================
Alex Vinokur
mailto:alexvn AT bigfoot DOT com
mailto:alexvn AT dr DOT com
http://up.to/alexvn
http://go.to/alexv_math
===========================
- Raw text -