Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilpropheta/404d346da720a364aabc29bcbeb5ae7b to your computer and use it in GitHub Desktop.
Save ilpropheta/404d346da720a364aabc29bcbeb5ae7b to your computer and use it in GitHub Desktop.
string res(char_needed, 0);
sprintf(res.data(), "%d", intNumber);
@pepsiman
Copy link

pepsiman commented Jun 5, 2016

I think you'd need to resize afterwards:

string res(char_needed); res.resize(sprintf(res.data(), "%d", intNumber));

@ilpropheta
Copy link
Author

Yeah, it's definitely better, even if res is actually filled with zeros so successive operations on the string should take this information into account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment