力为的技术博客

联系 聚合 管理
  154 Posts :: 1 Stories :: 561 Comments :: 0 Trackbacks
问题:
把以下字符串按照空格split
string str="   50  4    13.900     0.400    -0.600";

“方案”一:
用boost::split
#include "boost/algorithm/string.hpp"
std::vector<string> arrItem;
boost::split(arrItem, str, boost::is_any_of(" "));

使用以上代码不能达到目的。问题出在哪里?
posted on 2012-10-06 12:21 力为 阅读(2005) 评论(2)  编辑 收藏 引用 所属分类: 4. C++ FAQ

评论

# re: 【找茬】split string 2012-10-06 23:47 某某
boost::split(arrItem, str, boost::is_any_of(" "));
arrItem.erase(
std::remove(arrItem.begin(), arrItem.end(), ""),
arrItem.end());
std::copy(arrItem.begin(), arrItem.end(),
std::ostream_iterator<string>(std::cout, "\n"));


luckycpp@163.com  回复  更多评论
  

# re: 【找茬】split string 2012-10-08 10:01 hope
each space is regarded as a delimiter, if you don't specify the last parameter(token_compress_off/_on) of boost::split.  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理