c++stringuint64

C++ convert string to uint64_t


I am trying to convert from a string to a uint64_t integer. stoi returns a 32 bit integer, so it won't work in my case. Are there other solutions?


Solution

  • Try this:

    #include <iostream>
    #include <sstream>
    #include <cstdint>
    
    int main() {
        uint64_t value;
        std::istringstream iss("18446744073709551610");
        iss >> value;
        std::cout << value;
    }
    

    See Live Demo


    That may work for out of date standards too.