Jul 16, 2008 at 1:16am UTC
In this content, s1, s2 and s3 are strings
If I wanna combine s1 and s2 into s3. Is there any related code that can used from library?
The string S3 should be like S3[S1+S2]
Jul 16, 2008 at 1:30am UTC
Last edited on Jul 16, 2008 at 1:32am UTC
Jul 16, 2008 at 4:13am UTC
you can try the srtcat command. it concatenates two strings and would result in an output just like the kind you want.
hope this helps
Jul 16, 2008 at 8:24am UTC
Last edited on Jul 16, 2008 at 8:25am UTC
Jul 16, 2008 at 7:26pm UTC
@Zaita
That really works? =O
My god it does. So then whats the point of all of these other ways to do it?
Last edited on Jul 16, 2008 at 7:29pm UTC
Jul 16, 2008 at 8:20pm UTC
strcpy, strcat and printf are inherited from C.
s3.append() is more useful when appending char[] or char* to a string. It has issues when you do something like string s = string + char [] + char [] + string + etc
. I typically do string s = string + string(char []) + etc
. But .append() works too :)
Jul 16, 2008 at 8:22pm UTC
s1 + s2
is just a pretty way of writing
s1.append(s2)
,
which internally does something like
1 2
s1.reserve( s1.length() + s2.length() );
char_traits <char > ::copy( s1.internal_data +s1.length(), s1.internal_data, s2.length() );
[edit] too slow... :-)
Last edited on Jul 16, 2008 at 8:22pm UTC