使用标准库
#include <iostream> #include <vector> #include <string> #include <sstream> using namespace std; std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) { std::stringstream ss(s); std::string item; while (std::getline(ss, item, delim)) { if (!item.empty()){ elems.push_back(item); } } return elems; } std::vector<std::string> split(const std::string &s, char delim) { std::vector<std::string> elems; split(s, delim, elems); return elems; } int main(){ string s = "string to split a"; vector<string> columns = split(s, '\t'); for (vector<string>::iterator it = columns.begin(); it != columns.end(); it++){ cout << *it << endl; } return 0; }
使用boost
#include <iostream> #include <boost/algorithm/string.hpp> #include <vector> #include <string> using namespace std; int main(){ string s = "string to split a"; vector<string> strs; boost::split(strs, s , boost::is_any_of("\t")); for (vector<string>::iterator it = strs.begin(); it != strs.end(); it++){ cout << *it << endl; } return 0; }
相关推荐
Boost程序库完全开发指南:深入C++“准”标准库+Boost程序库完全开发指南:深入C++“准”标准库+Boost程序库完全开发指南:深入C++“准”标准库+Boost程序库完全开发指南:深入C++“准”标准库+Boost程序库完全开发...
超越c++标准库——boost程序库导论 对于学习boost库或TR1库是最有用的文档...
超越c++标准库 - boost程序库导论
C++的最新标准(C++11)已经正式公布,而早在这之前,Boost就已经使用库的形式实现了大部分新功能——而且是完全基于C++98标准实现的,内容涵盖智能指针、文本处理、并发、模板元编程等许多领域,其范围之广内涵之深...
大部分boost库功能的使用只需包括相应头文件即可,少数(如正则表达式库,文件系统库等)需要链接库。里面有许多具有工业强度的库,如graph库。STL集中在算法部分,而boost包含了不少工具类,可以完成比较具体的工作...
超越C++标准库:Boost库导论 美)卡尔森.著.张杰
[超越C++标准库:Boost库导论].(美)卡尔森.著.张杰良.译.扫描版.pdf
Boost程序库完全开发指南_深入C++准标准库.part2.rar
作为C++的准标准库,在C++的开发中的地位已经变得很重要了,自从发现了这本书后,我就开始迫不及待看起来。但是,从网上下载的许多pdf都是没有目录的,要么就是加密了的,所以我下载下来经过几天的编辑,终于做好了...
Boost库是一个经过千锤百炼、可移植、提供源代码的C++库,作为标准库的后备,是C++标准化进程的发动机之一。 Boost库由C++标准委员会库工作组成员发起,其中有些内容有望成为下一代C++标准库内容。 Boost中比较有...
c++通过boost库实现字符串之间与数字之间的
Boost库可以与C++标准库完美共同工作,并且为其提供扩展功能。Boost库使用Boost License来授权使用,根据该协议,商业的非商业的使用都是允许并鼓励的。 Boost社区建立的初衷之一就是为C++的标准化工作提供可供参考...
超越c++标准库boost程序库导论.rar
Boost项目(Boost C++ Libraries)是一个广泛使用的C++库集合,它提供了一系列广泛使用的任务和功能的实现,如智能指针、图形处理、数值分析、字符串和文本处理等。这些库几乎支持所有主流的操作系统,包括Windows、...
boost-stl是将来的c++标准库 这是关于这个库的一些文章chm合集
c++boost库最新版本
超越C++标准库-boost程序库导论超越C++标准库-boost程序库导论
Beyond the C++ Standard Library: An Introduction to Boost By Björn Karlsson ............................................... Publisher: Addison Wesley Professional Pub Date: August...
Boost程序库完全开发指南-深入C++“准”标准库高清版 罗剑锋著