Boost regex库 中的 split示例
来源:互联网 发布:round函数 mysql 编辑:程序博客网 时间:2024/05/17 00:01
//分开字符串
//编译方法: g++ -o reg_split -lboost-regex-gcc reg_split.cpp
#include <list>
#include <boost/regex.hpp>
unsigned tokenise(std::list<std::string>& l, std::string& s)
{
return boost::regex_split(std::back_inserter(l), s);
}
#include <iostream>
using namespace std;
#if defined(BOOST_MSVC) || (defined(__BORLANDC__) && (__BORLANDC__ == 0x550))
//
// problem with std::getline under MSVC6sp3
istream& getline(istream& is, std::string& s)
{
s.erase();
char c = is.get();
while(c != '/n')
{
s.append(1, c);
c = is.get();
}
return is;
}
#endif
int main(int argc)
{
string s;
list<string> l;
do{
if(argc == 1)
{
cout << "Enter text to split (or /"quit/" to exit): ";
getline(cin, s);
if(s == "quit") break;
}
else
s = "This is a string of tokens";
unsigned result = tokenise(l, s);
cout << result << " tokens found" << endl;
cout << "The remaining text is: /"" << s << "/"" << endl;
while(l.size())
{
s = *(l.begin());
l.pop_front();
cout << s << endl;
}
}while(argc == 1);
return 0;
}
//编译方法: g++ -o reg_split -lboost-regex-gcc reg_split.cpp
#include <list>
#include <boost/regex.hpp>
unsigned tokenise(std::list<std::string>& l, std::string& s)
{
return boost::regex_split(std::back_inserter(l), s);
}
#include <iostream>
using namespace std;
#if defined(BOOST_MSVC) || (defined(__BORLANDC__) && (__BORLANDC__ == 0x550))
//
// problem with std::getline under MSVC6sp3
istream& getline(istream& is, std::string& s)
{
s.erase();
char c = is.get();
while(c != '/n')
{
s.append(1, c);
c = is.get();
}
return is;
}
#endif
int main(int argc)
{
string s;
list<string> l;
do{
if(argc == 1)
{
cout << "Enter text to split (or /"quit/" to exit): ";
getline(cin, s);
if(s == "quit") break;
}
else
s = "This is a string of tokens";
unsigned result = tokenise(l, s);
cout << result << " tokens found" << endl;
cout << "The remaining text is: /"" << s << "/"" << endl;
while(l.size())
{
s = *(l.begin());
l.pop_front();
cout << s << endl;
}
}while(argc == 1);
return 0;
}
- Boost regex库 中的 split示例
- Boost regex库 中的 split示例
- Boost::Regex代码示例
- Boost::Regex代码示例
- Boost::Regex代码示例
- boost::regex示例代码
- boost库中的split函数
- boost::regex库中的boost::regex_replace方法学习
- Boost正则表达式库regex常用search和match示例
- boost 库Regex使用
- 【Boost】regex库
- Boost库regex VS2008
- VS2008编译boost正则表达式库Regex过程中的注意事项
- boost库 -- regex正则表达式
- Boost.Regex库学习笔记
- Boost.Regex库使用实例
- Boost.Regex库学习笔记
- Boost.Regex库 正则表达式
- 开始我的Sleep In Code之旅!
- 有些事并不是你看到的样子
- 学习组件设计
- MYSQL4.1版本的问题
- 真正标准,规范的企业网站建设合同书
- Boost regex库 中的 split示例
- Mq quick profile.
- 《Windows程序设计》读书笔记之一
- 2005-2-25 jsp 导出excel
- 【转载】→随笔:谁是盛大的头号竞争对手?
- UNIX的高级I/O
- 注重细节,走可持续发展之路
- GetPartFilter+SumStocklist
- 进程间通信IPC