|
From: James G. <Jam...@Cl...> - 2000-12-08 09:07:36
|
Your using strstream the wrong way, in the code below I'm using ostrstream
(output string stream) to be able to use the << operators.
#include <string>
#include <iostream>
#include <strstream>
using namespace std;
int main(int argc, char *argv[])
{
string MyString;
char MyChar[200];
((MyString += "John has ") += "4") += " apples!";
cout << MyString << endl;
// Wrap the char in an ostratream to enable the use of '<<' operator the
same as cout etc.
ostrstream(MyChar, sizeof(MyChar)) << "John has " << 10 << " apples!" <<
ends;
MyString = MyChar;
cout << MyString << endl;
return 0;
}
Regards,
James.
-----Original Message-----
From: Chad Simmons [mailto:ho...@ho...]
Sent: Thursday, December 07, 2000 4:58 PM
To: dev...@li...
Subject: RE: [Dev-C++] string-version of '+'
Sorry, I need to clarify.. It's the
MyString = MyStream.str();
line that the compiler bombs on.
This other line with the parentheses is ok.
((MyString += "John has ") += "4") += " apples!";
Chad Simmons
>From: "Chad Simmons" <ho...@ho...>
>Reply-To: dev...@li...
>To: dev...@li...
>Subject: RE: [Dev-C++] string-version of '+'
>Date: Thu, 07 Dec 2000 08:44:28 -0800
>
>Interesting.. I decided to actually test the code I was promoting, and I
>found a problem with the compiler.. It seems to bomb out on this bit of
>code..
>
>#include <string>
>#include <iostream>
>#include <strstream>
>using namespace std;
>
>int main(int argc, char *argv[])
>{
> string MyString;
> strstream MyStream;
>
> ((MyString += "John has ") += "4") += " apples!";
>
> cout << MyString << endl;
>
> MyStream << "John has " << 10 << " apples!";
>
> MyString = MyStream.str();
>
> cout << MyString << endl;
>
> return 0;
>}
____________________________________________________________________________
_________
Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
This electronic message and any attachment is intended to be
read by the named addressee(s) only.
Any other recipient should be aware that its contents may be
legally privileged and/or confidential and that its use,
disclosure, copying or distribution may be unlawful.
Unless you are a named addressee, please delete this message
Whilst C. & J. Clark International Limited has taken steps
to prevent the transmission of computer viruses with electronic mail,
responsibility for screening incoming messages and the risk of such
transmission and its consequences lies with the recipient.
C. & J. Clark International Limited
Registered in England and Wales
Company No. 141015
Registered Office: 40 High Street, Street, Somerset BA16 0YA
Telephone: +44 (0) 1458 443131
Fax: +44 (0) 1458 447547
|