__int64, - . , .
Boost lexical cast - . :
__int64 x = boost::lexical_cast<__int64>("3473472936");
boost, . , :
template <typename R>
const R lexical_cast(const std::string& s)
{
std::stringstream ss(s);
R result;
if ((ss >> result).fail() || !(ss >> std::ws).eof())
{
throw std::bad_cast();
}
return result;
}
It performs some additional functions, such as checking for trailing characters. ( "123125asd"will fail). If the throw cannot be made, it is thrown bad_cast. (Like boost.)
Also, if you have access to boost, you can avoid the need to use an __int64MSVC-enabled extension with
#include <boost/cstdint.hpp>
typedef boost::int64_t int64;
Get int64on any platform that provides it, without changing the code.
source
share