如何使用C ++从字符串中删除前导零? [英] How to remove leading zeros from string using C++?
本文介绍了如何使用C ++从字符串中删除前导零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从字符串中删除前导零,例如"0000000057"
.
I want to remove leading zeroes from string like "0000000057"
.
我确实喜欢这样,但没有得到任何结果:
I did like this but didn't get any result:
string AccProcPeriNum = strCustData.substr(pos, 13);
string p48Z03 = AccProcPeriNum.substr(3, 10);
我只希望输出 57 .
在C ++中有任何想法吗?
Any idea in C++?
推荐答案
#include <string>
std::string str = "0000000057";
str.erase(0, str.find_first_not_of('0'));
assert(str == "57");
这篇关于如何使用C ++从字符串中删除前导零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文