#include <iostream>
#include <boost/regex.hpp>
usingnamespace std;
int main(int argc)
{
string s;
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";
boost::regex re("\\s+");
boost::sregex_token_iterator i(s.begin(), s.end(), re, -1);
boost::sregex_token_iterator j;
unsigned count = 0;
while(i != j)
{
cout << *i++ << endl;
count++;
}
cout << "There were " << count << " tokens found." << endl;
}while(argc == 1);
return 0;
}
Question: is there a nicer way to figure out when the iterator "i" ends rather than comparing it to "j" (in the while loop) defined just for this purpose ?
Or does it require analysis of the regex_token_iterator template ? If so, I shall investigate it later when I read up on templates :)