主要应用头文件
#include <boost/cstdint.hpp>
#include <sstream>
方法1
输出 ff
方法2
不应用boost整数类型
方法3
不应用boost整数类型
#include <boost/cstdint.hpp>
#include <sstream>
方法1
boost::uint16_t number = 255;
std::stringstream convertor;
convertor.setf(std::ios::hex,std::ios::basefield);
convertor<<static_cast<int>(number);
string str = convertor.str();
cout<<str<<endl;
输出 ff
方法2
不应用boost整数类型
int number = 255;
std::stringstream convertor;
convertor<<std::hex<<number;
string str = convertor.str();
cout<<str<<endl;
方法3
不应用boost整数类型
int number = 255;
std::stringstream convertor;
convertor.setf(std::ios::hex,std::ios::basefield);
convertor<<number;
string str = convertor.str();
cout<<str<<endl;