该程序用于去除字符串开头的零字符。当输入"0000123456"时,程序会输出"123456"。核心函数removeZero()通过while循环找到第一个非零字符的位置,然后使用erase()方法删除前面的所有零。主函数读取输入字符串并调用该函数处理。程序简洁高效,适用于需要去除前导零的场景。
输入
0000123456
输出
123456
#include<bits/stdc++.h>
using namespace std;
string removeZero(string str){int i=0;while(str[i]=='0'){i++;}str.erase(0,i);return str;
}
int main(){string str;cin>>str;cout<<removeZero(str);return 0;
}