Created
January 1, 2017 20:17
-
-
Save ilpropheta/ec12b8dccae93132aede78f73ffb90e8 to your computer and use it in GitHub Desktop.
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
int to_int(string_view sv) | |
{ | |
char formatter[24] = {}; | |
sprintf(formatter, "%%%zud%%n", sv.size()); | |
int num, n{0}; | |
if (sscanf_s(sv.data(), formatter, &num, &n)==1 && n==sv.size()) // could emit a warning because sv.size() is unsigned | |
return num; | |
else // (some) error handling | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment