C++ C++;Boost:Split函数是()
我试图在以下函数中使用C++ C++;Boost:Split函数是(),c++,boost,C++,Boost,我试图在以下函数中使用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
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;
}
vector splitString(字符串输入,字符串轴){//pivot:例如“##”
vector splitInput;//拆分和存储字符串的向量
split(splitInput,input,is_any_of(pivot),token_compress_on);//拆分字符串
返回输入;
}
以下电话:
string hello = "Hieafds##addgaeg##adf#h";
vector<string> split = splitString(hello,"##"); //Split the string based on occurrences of "##"
string hello=“Hieafds##addgaeg##adf#h”;
向量拆分=拆分字符串(您好,“##””//根据“##”的出现情况拆分字符串
将字符串拆分为“Hieafds”“addgaeg”“adf”
和“h”
。但是,我不希望字符串被单个#
拆分。我认为问题出在的is any of()
上
该如何修改函数,使字符串仅由出现的
“##”
拆分?没错,您必须使用is#any_of()
请看一下。嘿,对不起。我在发布代码时出错。我一看到你的答案就马上改正了。我的意思是,如果我使用
is_any_of()
它会检查轴中的任何字符,并相应地拆分。但是我只想在pivot完全匹配的情况下分割它。这个答案不应该被否决,因为它回答了一个原始的、稍有错误的问题版本(后来被编辑)。尝试使用split_regex:Thank=)我想它是行得通的。另外,你可以使用iter_分割(vec,str,first_finder(“###”);(见以下答案:)
std::string input = "some##text";
std::vector<std::string> output;
split( output, input, is_any_of( "##" ) );
split_regex( output, input, regex( "##" ) );