Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何将 a 转换为std::stringa uint64_t?如果字符串不包含uint64_t. 例如,这些的转换应该抛出:
std::string
uint64_t
"NO: 9889" "9889L" "9889U" "1e+22"
或通过其他方式表明它们不是纯粹的表示。我正在使用 C++98 和 boost(包括boost::regex)。
boost::regex
使用boost::lexical_cast. bad_lexical_cast如果数字无法解析或溢出,它将抛出一个。
boost::lexical_cast
bad_lexical_cast
如果您曾经切换到 C++11,标准中有一个新功能应该更快。
A后跟 a始终是一个选项for。isdigit()strtoll()
for
isdigit()
strtoll()
也许不是单行,而是在您的 stringutils.cpp 中编写的一个很好的函数。