asprintf() ( ), :
char* p;
int num_chars = asprintf(&p, "%s%s", a, b);
, printf(), , ints, double .., , , .. num_chars!= -1 ( ), p , free(). asprintf() .
++:
std::string result = std::string(a) + b;
: a + b - , , + std::string, , .
(The accepted answer strncatdeserves further comment: it can be used to combine more textual data after the ASCIIZ string in an existing, writable buffer, since there is free space in this buffer. It cannot safely / portable concatenate into a string literal, and it still hurts to create such a buffer . If you do this with the help malloc()to ensure its correct length, then strcat()you can use it, preferring it strncat()anyway.)
source
share