Home > Software engineering >  converting boost::multiprecision::int256_t to string
converting boost::multiprecision::int256_t to string

Time:02-20

how would I convert a boost::multiprecision::int256_t type variable into a string for example if i have

string string1 = "12345";
boost::multiprecision::int256_t int1 (string1);
boost::multiprecision::int256_t int2 = int1   5
string string2;
// how do i making string equivalent to int2

CodePudding user response:

I think you just use the str() method on the multiprecision number.

[Demo]

#include <iostream>  // cout
#include <string>

#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;

int main()
{    
    std::string string1 = "12345";
    boost::multiprecision::int256_t int1 (string1);
    boost::multiprecision::int256_t int2 = int1   5;
    std::string string2{ int2.str() };
    std::cout << string2 << "\n";
}

// Outputs:
//
//   12350
  • Related