|
From: James G. <Jam...@Cl...> - 2000-12-07 16:09:47
|
this might not be the best way but I've always had to split the code into
two statements.
Change this:
myString = "John has " + myApples + " apples";
To this:
myString = "John has " + myApples;
myString += " apples";
This is because it works from right to left.
In your code you are trying to assign the string " apples" to the char[20]
and the result from that to the string "John has " and then that lot to the
std::string.
I think that's correct...
Regards,
James.
-----Original Message-----
From: Gregor Peter [mailto:Gre...@dl...]
Sent: Thursday, December 07, 2000 2:58 PM
To: exc...@sp...; dev...@li...
Subject: [Dev-C++] string-version of '+'
You're right!
I tried it before in a direkt manner which doesn't work :-(
string myString;
char myApples[20];
int myInt;
itoa( myInt, myApples, 10);
myString = "John has " + myApples + " apples";
I get following error message:
invalid operands `const char[28]' and `char[20]' to binary `operator +'
How do I enshure to use the string-version of '+' instead of the integer?
Gregor
> string my1String("John has");
> string my2String("apples!");
> char myApples[20] ;
> int myInt = 6;
>
> itoa(myInt, myApples, 10);
>
> my1String = my1String + myApples + my2String ;
>
> That is you can put all of the strings into one, my1String.
_______________________________________________
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
|