在 C++ MD2 文件加载器中,我有很多帧,每个帧的名称都以数字结尾,例如
- stand0
- 展位1
- 站2
- stand3
- stand4
- ...
- 10号展台
- stand11
- 运行0
- 第一轮
- 第二轮
等等
如何得到没有后面数字的字符串?例如将“stand10”更改为“stand”的函数
最佳答案
只是为了展示另一种方式,反向迭代器:
string::reverse_iterator rit = str.rbegin();
while(isdigit(*rit)) ++rit;
std::string new_str(str.begin(), rit.base());
如果你有 boost::bind,你可以让你的生活更轻松
std::string new_str(str.begin(),
std::find_if(str.rbegin(), str.rend(),
!boost::bind(::isdigit, _1)).base());
关于c++ - 检查字符串在 C++ 中以什么数字结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/538300/