c++ - 如何从字符串末尾提取数字

标签 c++ c stl

给定如下字符串:

   sdfsd34 
    sdfdsf1

我想提取:34, 1 使用 c++(STL 但没有提升),c。

谢谢

最佳答案

您正在搜索函数 string.find_last_not_of :

string str = "sdfsd34";
size_t last_index = str.find_last_not_of("0123456789");
string result = str.substr(last_index + 1);

关于c++ - 如何从字符串末尾提取数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4072363/

相关文章:

c++ - 如何使 linux 命令行程序在 windows 中运行?

c# - 在与 STL 混合的 C# 中调用非托管 C++ 代码

c++ - 尝试将元素插入 vector

c++ - 使用 std::unique 和 vector.erase 删除除了最后一次出现的所有重复元素

c++ - delete[] (ptr, 0) 的行为

c++ - union 数组有效还是无效?

c++ - 在 C++ 中将字符串转换为数字

c++ - 计算文件中单词频率的优雅方法

c - 如何解决错误 "Segmentation fault (core dumped)"

c - GHC/FFI : calling haskell module which imports haskell libraries from C