and
のいずれかの文字列を分割したい。C++分割文字列全体として別の文字列
最初に、私は区切り文字としてregex
を使用するつもりはないことを明確にしなければなりません。
私は次のコードを実行します。
#include <iostream>
#include <regex>
#include <boost/algorithm/string.hpp>
int main()
{
std::vector<std::string> results;
std::string text=
"Alexievich, Svetlana and Lindahl,Tomas and Campbell,William";
boost::split(
results,
text,
boost::is_any_of(" and "),
boost::token_compress_off
);
for(auto result:results)
{
std::cout<<result<<"\n";
}
return 0;
}
をし、結果は私が期待するものとは異なります。
Alexievich,
Svetl
Li
hl,Tom
s
C
mpbell,Willi
m
私が全体を持っている必要がありながら、区切りのすべての文字が個別に動作するようですand
を区切り文字として使用します。
this boost exampleにリンクしないでください。私の場合は問題なく動作します。
「is_any_of」とは、文字列内の任意の文字と一致するものです。 3番目の引数はlambdaを含む任意の呼び出し可能なオブジェクトであることを意味する*述語*です。別の問題は、[boost :: split'](http://www.boost.org/doc/libs/1_61_0/doc/html/boost/algorithm/split_idp205739088.html)が*文字ベースであるように見えることです。 「単語」に基づくものではありません。 –
@JoachimPileborg、ご意見ありがとうございます。交換するものは? – jeremine