boost::split in C++ library
This function is similar to strtok in C. Input sequence is split into tokens, separated by separators. Separators are given by means of the predicate.
Syntax:
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
Application : It is used to split a string into substrings which are separated by separators.
Example:
Input : boost::split(result, input, boost::is_any_of("\t"))
input = "geeks\tfor\tgeeks"
Output : geeks
for
geeks
Explanation: Here in input string we have "geeks\tfor\tgeeks"
and result is a container in which we want to store our result
here 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; } |
chevron_right
filter_none
Output:
geeks for geeks
Recommended Posts:
- <iterator> library in C++ STL
- <numeric> library in C++ STL
- <strings> library in C++ STL
- <algorithms> library in C++ STL
- SDL library in C/C++ with examples
- snprintf() in C library
- <regex> library in C++ STL
- Pattern Searching using C++ library
- Any datatype in C++ boost library
- The C++ Standard Template Library (STL)
- C Library math.h functions
- Map in C++ Standard Template Library (STL)
- Set in C++ Standard Template Library (STL)
- Advanced C++ with boost library
- difftime() C library function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


