将前导零添加到字符串,不带printf [英] Add leading zero's to string, without (s)printf

查看:82
本文介绍了将前导零添加到字符串,不带printf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要向字符串添加前导零的变量。
我在Google上找不到任何东西,没有人提到printf,
,但我想这样做没有printf。

I want to add a variable of leading zero's to a string. I couldn't find anything on Google, without someone mentioning (s)printf, but I want to do this without (s)printf.

推荐答案

// assuming that `original_string` is of type `std:string`:

std::string dest = std::string( number_of_zeros, '0').append( original_string);

这篇关于将前导零添加到字符串,不带printf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆