| 1 | #include <list>
|
|---|
| 2 | #include <boost/algorithm/string/finder.hpp>
|
|---|
| 3 | #include <boost/algorithm/string/split.hpp>
|
|---|
| 4 | #include <boost/foreach.hpp>
|
|---|
| 5 |
|
|---|
| 6 | using namespace std;
|
|---|
| 7 | using namespace boost;
|
|---|
| 8 | using boost::algorithm::find_all;
|
|---|
| 9 |
|
|---|
| 10 | int main(int argc, char* argv[])
|
|---|
| 11 | {
|
|---|
| 12 | std::string haystack("AAAA");
|
|---|
| 13 | std::string needle("AAA");
|
|---|
| 14 |
|
|---|
| 15 | std::list<boost::iterator_range<std::string::iterator>> out;
|
|---|
| 16 | boost::algorithm::find_all(out, haystack, needle);
|
|---|
| 17 |
|
|---|
| 18 | cout << "matches=" << out.size() << endl;
|
|---|
| 19 |
|
|---|
| 20 | BOOST_FOREACH(boost::iterator_range<std::string::iterator> it, out)
|
|---|
| 21 | {
|
|---|
| 22 | cout << (it.begin() - haystack.begin()) << ' ';
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | cout << endl;
|
|---|
| 26 |
|
|---|
| 27 | return 0;
|
|---|
| 28 | }
|
|---|