十进制到十六进制转换c ++内置函数 [英] Decimal to hex conversion c++ built-in function
本文介绍了十进制到十六进制转换c ++内置函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在c ++中是否有一个内置函数会从用户处取得十进制输入并将其转换为十六进制,反之亦然?我已经尝试过使用我编写的函数,但是我想知道是否有内置的函数来最小化代码。
Is there a built-in function in c++ that would take a decimal input from a user and convert it to hex and vice versa?? I have tried it using a function I've written but I was wondering if there is a built-in one to minimize the code a little bit. Thanks in advance.
推荐答案
十进制到十六进制: -
Decimal to hex :-
std::stringstream ss;
ss<< std::hex << decimal_value; // int decimal_value
std::string res ( ss.str() );
std::cout << res;
十六进制到十进制: - $ /
Hex to decimal :-
std::stringstream ss;
ss << hex_value ; // std::string hex_value
ss >> std::hex >> decimal_value ; //int decimal_value
std::cout << decimal_value ;
参考: std :: hex
, std :: stringstream
这篇关于十进制到十六进制转换c ++内置函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文