我需要进行字符串拆分,以便如果我有如下所示的字符串

string foo="thisIsThe         Test     Input";


我需要让部分出现在多个或单个空格之后。在这种情况下,我需要获取"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++ - C++拆分字符串并使部分在空格之后,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20809727/

10-08 22:03
查看更多