c – boost :: split在字符串的开始和结尾留空空标志 – 这是期
发布时间:2020-12-16 05:56:21 所属栏目:百科 来源:网络整理
导读:由于我在 documentation年找不到任何东西,所以我以为我在这里问.我有以下程序(C 11): #include iostream #include boost/algorithm/string.hppusing namespace std;using namespace boost;int main () { string tmp = " #tag #tag1#tag2 #tag3 ####tag4 ";
由于我在
documentation年找不到任何东西,所以我以为我在这里问.我有以下程序(C 11):
#include <iostream> #include <boost/algorithm/string.hpp> using namespace std; using namespace boost; int main () { string tmp = " #tag #tag1#tag2 #tag3 ####tag4 "; list<iterator_range<string::iterator> > matches; split( matches,tmp,is_any_of("t #"),token_compress_on ); for( auto match: matches ) { cout << "'" << match << "'n"; } } 输出为: '' 'tag' 'tag1' 'tag2' 'tag3' 'tag4' '' 我会认为token_compress_on选项删除所有空的令牌. (g 4.6.3,升压1.48) 解决方法
行为是故意的,因为您可以从拆分版本重新创建字符串(包括起始和尾随空格). Boost不知道这个空格是否对您有重要意义(可能是因为某些文件格式可能会强制引导空格/特定的空格).
如果您需要删除前导/尾随空格,您应该按照您的要求修剪或修剪. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |