整数转字符串
//支持負(fù)數(shù)轉(zhuǎn)字符串
std::string num_to_str(const int value)
{
?? ?std::string str;
?? ?std::string falg;
?? ?int temp_value = value;
?? ?int falg_pos = temp_value >> 31;//判斷符號位
?? ?if (falg_pos < 0) {
?? ??? ?falg += "-";
?? ??? ?temp_value = ((~temp_value) + 1);//負(fù)變正,正變負(fù)
?? ?}
?? ?while (temp_value >0){
?? ??? ?str += temp_value % 10 + '0';
?? ??? ?temp_value /= 10;
?? ?}
?? ?
?? ?//逆序
?? ?size_t right_idex = str.size() - 1;
?? ?size_t left_index = 0;
?? ?while (left_index <right_idex){
?? ??? ?char temp = str[left_index];
?? ??? ?str[left_index++] = str[right_idex];
?? ??? ?str[right_idex--] = temp;
?? ?}
?? ?falg += str;
?? ?return std::move(falg);
}
總結(jié)
- 上一篇: Jenkins 与 Kubernetes
- 下一篇: VituralBox从零搭建基于Cent