~
[scx.git] / misc / split.cpp
blobe539a0076ed4d3376c84017651dbe0a2844fba4d
1 #include <iostream>
2 #include <vector>
3 #include <string>
4 #include <sstream>
5 #include <iterator>
6 #include <algorithm>
7 using namespace std;
9 template<typename item_t, typename iter_t>
10 void CoutEachItem(iter_t begin, iter_t end, const string& space = "\n")
12 std::copy(begin, end, std::ostream_iterator<item_t>(cout, space.c_str()));
15 int main()
17 vector<string> tokens;
18 string sentence = "something a like you? ...";
19 istringstream iss(sentence);
21 copy(istream_iterator<string>(iss),
22 istream_iterator<string>(),
23 back_inserter<vector<string> >(tokens));
25 CoutEachItem<string>(tokens.begin(), tokens.end(), "|");
27 copy(istream_iterator<string>(iss),
28 istream_iterator<string>(),
29 ostream_iterator<string>(cout, "\n"));
32 return 0;