I need to convert a (decimal, if it matters) string representation of a number input from a text file to a UINT64 to pass to my data object.
size_t startpos = num.find_first_not_of(" ");
size_t endpos = num.find_last_not_of(" ");
num = num.substr(startpos, endpos-startpos+1);
UINT64 input;
//convert num to input required here
Is there any way to convert an std::string to a UINT64 in a similar way to atoi()?
Thanks!
Edit: Working code below.
size_t startpos = num.find_first_not_of(" ");
size_t endpos = num.find_last_not_of(" ");
num = num.substr(startpos, endpos-startpos+1);
UINT64 input; //= std::strtoull(num.cstr(), NULL, 0);
std::istringstream stream (num);
stream >> input;
Use strtoull or _strtoui64(). Example:
std::string s = "1123.45";
__int64 n = std::strtoull(s.c_str(),NULL,0);