拆分string 用空格 逗号
2014-04-15 11:54
162 查看
stringthathavebothcommaandspace
structtokens:std::ctype<char>{ tokens():std::ctype<char>(get_table()){}staticstd::ctype_base::maskconst*get_table(){typedefstd::ctype<char>cctype;staticconstcctype::mask*const_rc=cctype::classic_table();staticcctype::maskrc[cctype::table_size]; std::memcpy(rc,const_rc,cctype::table_size*sizeof(cctype::mask)); rc[',']=std::ctype_base::space; rc['']=std::ctype_base::space;return&rc[0];}}; std::strings="rightway,wrongway,correctway"; std::stringstreamss(s); ss.imbue(std::locale(std::locale(),newtokens())); std::istream_iterator<std::string>begin(ss); std::istream_iterator<std::string>end; std::vector<std::string>vstrings(begin,end); std::copy(vstrings.begin(),vstrings.end(),std::ostream_iterator<std::string>(std::cout,"\n")); ——————————————————————————————————————————————————————————————————————————
只有空格: trings="Whatistherightwaytosplitastringintoavectorofstrings"; std::stringstreamss(s); std::istream_iterator<std::string>begin(ss); std::istream_iterator<std::string>end; std::vector<std::string>vstrings(begin,end); std::copy(vstrings.begin(),vstrings.end(),std::ostream_iterator<std::string>(std::cout,"\n"));
相关文章推荐
- 程序员写的产品经理指南(一、产品经理不应该是产品蝗虫)
- 约瑟夫环
- 导出Excel And 导出word
- 后台转换JSON格式。ToJson
- cmd执行调用打开文件
- Java中的各种bean对应的意义(VO,PO,BO,QO, DAO,POJO,DTO)
- NYOJ-17 单调递增最长子序列 两种方法(动态规划,贪心+二分查找)
- xmpp学习3
- XML解析方式
- Linux 压缩解压命令
- MFC CEvent 事件
- iOS7.1企业应用"无法安装应用程序 因为证书无效"的解决方案
- c#反射调用方法示例
- JSON格式
- 可在广域网部署运行的QQ高仿版 -- GG叽叽V3.0,完善基础功能(源码)
- xmpp学习2
- 在Myeclipse中搭建和使用Hibernate
- 问题
- 青蛙跳台阶
- iOS UIView 圆角