如何从c++中的字符串中减去字符?
您好,我想知道如何从字符串中划分字符串,
例如
字符串s =“ 124ab” 我可以通过使用Sstream轻松提取整数,但我不知道如何提取
要从S提取AB的字符串; 我有大量的字符串,它们没有任何规则。 S可以是“ 3456fdhgab”或“ 34a678”
Hello I want to know how to subract string from string
For example
If string s = "124ab"
I can easily extract integer by using sstream but I don't know how to extract string
I want to extract ab from s;
I have tons of string and they don't have any rule.
s can be "3456fdhgab" or "34a678"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
std :: isDigit
检查字符是否是数字。您可以使用 erase-remove idiom 。因为
std :: isDigit
具有超载,必须将其包裹在lambda中才能在算法中使用:output :
由于您要求使用Stringstream,因此您可以使用自定义
操作员<<<
:输出:
You can use
std::isdigit
to check if a character is a digit. You can use the erase-remove idiom to remove characters that are digits.Because
std::isdigit
has an overload it has to be wrapped in a lambda to be used in the algorithm:Output:
And because you asked for using a stringstream, here is how you can extract non-digits with a custom
operator<<
:Output: