Skip to content

Instantly share code, notes, and snippets.

@morxa
Last active August 29, 2015 14:03
Show Gist options
  • Save morxa/5e895c44eb2565f21d02 to your computer and use it in GitHub Desktop.
Save morxa/5e895c44eb2565f21d02 to your computer and use it in GitHub Desktop.
string concat with asprintf
std::string foo_string = "foo";
std::string bar_string = "bar";
std::string res;
char * tmp;
if (asprintf(&tmp, "concatenation: %s %s", foo_string.c_str(), bar_string.c_str()) != -1) {
res = tmp;
free(tmp);
} else {
throw Exception("Out of memory");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment