Last active
August 29, 2015 14:03
-
-
Save morxa/5e895c44eb2565f21d02 to your computer and use it in GitHub Desktop.
string concat with asprintf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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