おそらく誰かがここで何が起こっているのか教えてくれますか?
私の意図は、入力文字列を中括弧で分割することです。つまり、' ( 'または' ) 'のいずれかです。
「(well)hello(there)world」の入力文字列の場合、4つのトークンが返されることを期待しています。こんにちは; そこの; 世界。
以下の模範的なアプリからわかるように、5つのトークンが返されます(1つ目は空の文字列です)。
空でない文字列のみを返すようにこれを取得する方法はありますか?
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <vector>
int main()
{
std::string in = "(well)hello(there)world";
std::vector<std::string> tokens;
boost::split(tokens, in, boost::is_any_of("()"));
for (auto s : tokens)
std::cout << "\"" << s << "\"" << std::endl;
return 0;
}
出力:
$ a.out
"" <-- where is this token coming from?
"well"
"hello"
"there"
"world"
使ってみboost::algorithm::token_compress_on
ましたが、同じ結果になりました。