我需要做一个字符串拆分,这样如果我有一个如下所示的字符串
string foo="thisIsThe Test Input";
我需要在多个或单个 withspace 之后获取部分。在这种情况下,我需要获取 "Test Input"。
我知道我可以通过以下方式获取第一部分:
int index=foo.find(' ');
string subString=foo.substr(0,index);
但我不知道我怎么能做我想做的事。有人可以帮助我吗?
最佳答案
std::find_first_not_of
接受指示从何处开始搜索的位置参数。所以用它来找到第一个非空格,从第一个空格开始。
int index=foo.find(' ');
index=foo.find_first_not_of(' ', index);
string subString=foo.substr(index);
关于c++拆分字符串并获取空格之后的部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20809727/