Sorry if this is the wrong place to ask but I have just been toying around
with boost ad have come across the following:-
#include <iostream>
#include <boost/regex.hpp>
using namespace std;
void testSearch(const boost::regex &ex, const string st) {
cout << "Searching " << st << endl;
string::const_iterator start, end;
start = st.begin();
end = st.end();
boost::match_results<std::string::const_iteratorwh at;
boost::match_flag_type flags = boost::match_default;
while(boost::regex_search(start, end, what, ex, flags))
{
cout << " " << what.str() << endl;
start = what[0].second;
}
}
void carry_out(const string &asd)
{
static const boost::regex ex("[Rr]eg...r");
testSearch(ex, asd);
}
int main(int argc, char *argv[])
{
bool cont;
cont = 1;
while(cont)
{
cout << "Please enter a string: ";
string asd;
cin >asd;
carry_out(asd);
cout << "Do you wish to try another string: ";
cin >cont;
}
return 0;
}
If I enter anything other than 1 or 0 for cin >cont; I end up with an
endless loop. The cout's of the while loop as well as the testSearch
function continuosly get output without asking for an input.
There is probably a very good reason for this which I would just like to
know (I am just learning so I think it best to understand things like this).
I can understand that the variable would not get populated if the input was
not a bool but why endlessly looping? (the same happens if I put a space in
the iput string that goes through the regexp which maybe related but not
sure why.)
Any help appreciated.