此功能类似于C中的strtok。输入序列被拆分为标记, 并由分隔符分隔。分隔符是通过谓词给出的。
语法如下:
Template:split(Result, Input, PredicateT Pred);
Parameters:Input: A container which will be searched.Pred: A predicate to identify separators. This predicate is supposed to return true if a given element is a separator.Result: A container that can hold copies of references to the substrings.Returns: A reference the result
【如何使用C++库中的boost::split(示例)】应用范围:它用于将字符串拆分为由分隔符分隔的子字符串。
例子:
Input : boost::split(result, input, boost::is_any_of("\t"))input = "geeks\tfor\tgeeks"Output : geeksforgeeksExplanation: Here in input string we have "geeks\tfor\tgeeks"and result is a container in which we want to store our resulthere separator is "\t".
// C++ program to split
// string into substrings
// which are separated by
// separater using boost::split// this header file contains boost::split function
#include <
bits/stdc++.h>
#include <
boost/algorithm/string.hpp>
using namespace std;
int main()
{
string input( "geeks\tfor\tgeeks" );
vector<
string>
result;
boost::split(result, input, boost::is_any_of( "\t" ));
for ( int i = 0;
i <
result.size();
i++)
cout <
<
result[i] <
<
endl;
return 0;
}
输出如下:
geeksforgeeks
被认为是行业中最受欢迎的技能之一, 我们拥有自己的编码基础C ++ STL通过激烈的问题解决过程来训练和掌握这些概念。
推荐阅读
- 算法设计(如何计算两个链表的并集和交集())
- 如何使用jQuery将字符串的首字母转换为大写()
- 网络安全和信息安全之间有什么区别()
- win7下“菜式齐全”免费刻录“大餐”
- xp系统下自动定时关机,别忘Shutdown程序
- 虚拟内存不足的3大处理办法及9大缘由
- 不可或缺的Photoshopcs快捷键
- 高手教你恢复误删文件的秘籍
- 不可缺少的XP系统重装的小窍门