Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;Boost:Split函数是()_C++_Boost - Fatal编程技术网

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( "##" ) );