delorie.com/archives/browse.cgi | search |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sources.redhat.com/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
To: | cygwin AT cygwin DOT com |
Subject: | Re: stringstream vs. strstream |
References: | <8AC36D3167EED41184C800508BD9540502CF5D03 AT apollo DOT adtech-inc DOT com> |
From: | dmkarr AT earthlink DOT net (David M. Karr) |
Date: | 29 Jan 2002 09:43:54 -0800 |
In-Reply-To: | <8AC36D3167EED41184C800508BD9540502CF5D03@apollo.adtech-inc.com> |
Message-ID: | <868zahuk6d.fsf@earthlink.net> |
Lines: | 61 |
User-Agent: | Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp (Windows [1])) |
MIME-Version: | 1.0 |
>>>>> "Jimen" == Jimen Ching <Ching> writes: Jimen> Hi all, Jimen> Given this source code: Jimen> ---------------------------------------------------------------------- Jimen> #include <iostream> Jimen> #include <sstream> Jimen> #include <strstream> Jimen> #include <string> Jimen> int Jimen> main() Jimen> { Jimen> stringstream s1; Jimen> strstream s2; Jimen> string s, fmt("string"); Jimen> s1 << fmt[2]; Jimen> s1 << ends; Jimen> s = s1.str(); Jimen> cout << "s1: " << s << endl; Jimen> cout << "s1 size: " << s.size() << endl; Jimen> s2 << fmt[1]; Jimen> s2 << ends; Jimen> s = s2.str(); Jimen> cout << "s2: " << s << endl; Jimen> cout << "s2 size: " << s.size() << endl; Jimen> return 0; Jimen> } Jimen> ---------------------------------------------------------------- Jimen> The following output is generated: Jimen> $ uname -a Jimen> CYGWIN_NT-4.0 A19990524 1.3.9(0.51/3/2) 2002-01-21 12:48 i686 unknown Jimen> $ g++ -v Jimen> Reading specs from /bin/../lib/gcc-lib/i686-pc-cygwin/2.95.3-5/specs Jimen> gcc version 2.95.3-5 (cygwin special) Jimen> $ g++ tst.cc Jimen> $ ./a.exe Jimen> s1: r^@ Jimen> s1 size: 2 Jimen> s2: t Jimen> s2 size: 1 Jimen> Note, the shell used is bash. So the '^@' is what is printed on the Jimen> console. Jimen> My question is, why is stringstream and strstream behaving differently? Jimen> I think stringstream should behave like strstream. Comments? They behave differently because they are different. The newer "stringstream" class provides the capability to directly insert null characters, which the "ends" manipulator does. When you use "stringstream", don't use "ends" to null-terminate a string. It's not necessary. -- =================================================================== David M. Karr ; Java/J2EE/XML/Unix/C++ dmkarr AT earthlink DOT net -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |