我正在尝试在以下函数中使用位于boost/algorithm/string.hpp
的split()
函数:
vector<std::string> splitString(string input, string pivot) { //Pivot: e.g., "##"
vector<string> splitInput; //Vector where the string is split and stored
split(splitInput,input,is_any_of(pivot),token_compress_on); //Split the string
return splitInput;
}
下面的调用代码:
string hello = "Hieafds##addgaeg##adf#h";
vector<string> split = splitString(hello,"##"); //Split the string based on occurrences of "##"
将字符串分割为"Hieafds" "addgaeg" "adf"
和"h"
。但我不想用单个#
来分割字符串。 我认为问题在于is_any_of()
。
应如何修改函数,以仅通过"##"
的出现来拆分字符串?