Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::atoll with VC++

I have been using std::atoll from cstdlib to convert a string to an int64_t with gcc. That function does not seem to be available on the Windows toolchain (using Visual Studio Express 2010). What is the best alternative?

I am also interested in converting strings to uint64_t. Integer definitions taken from cstdint.

like image 682
Cookie Avatar asked Jul 07 '11 12:07

Cookie


2 Answers

MSVC have _atoi64 and similar functions, see here

For unsigned 64 bit types, see _strtoui64

like image 92
nos Avatar answered Nov 07 '22 23:11

nos


  • use stringstreams (<sstream>)

    std::string numStr = "12344444423223";
    std::istringstream iss(numStr);
    long long num;
    iss>>num;
    
  • use boost lexical_cast (boost/lexical_cast.hpp)

     std::string numStr = "12344444423223";
     long long num = boost::lexical_cast<long long>(numStr);
    
like image 20
Armen Tsirunyan Avatar answered Nov 07 '22 21:11

Armen Tsirunyan