// Separate strings
// Compilation method: g ++-o reg_split-lboost-regex-gcc reg_split.cpp
# Include <list>
# Include <boost/regex. hpp>
Unsigned tokenise (std: list <std: string> & l, std: string & s)
{
Return boost: regex_split (std: back_inserter (l), s );
}
# Include <iostream>
Using namespace std;
# If defined (BOOST_MSVC) | (defined (_ BORLANDC _) & (_ BORLANDC _ = 0x550 ))
//
// Problem with std: getline under MSVC6sp3
Istream & getline (istream & is, std: string & s)
{
S. erase ();
Char c = is. get ();
While (c! = '/N ')
{
S. append (1, c );
C = is. get ();
}
Return is;
}
# Endif
Int main (int argc)
{
String s;
List <string> l;
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 ";
Unsigned result = tokenise (l, s );
Cout <result <"tokens found" <endl;
Cout <"The remaining text is:/" "<s <"/"" <endl;
While (l. size ())
{
S = * (l. begin ());
L. pop_front ();
Cout <s <endl;
}
} While (argc = 1 );
Return 0;
}