
AMDG Wong Peter wrote:
Hello to all, i want to search a container which copied from file with certain regular expression and then display it to stdout;
Here is my code:
[code]
std::cout << "\n\nEnter Search designation : "; std::string userDesignation; getline(std::cin, userDesignation);
std::ifstream inHandle("C:\\Staff.txt"); std::vector<std::string> data; data.reserve(100); std::copy(std::istream_iterator<std::string>(inHandle), std::istream_iterator<std::string>(), std::back_inserter(data) );
This breaks the input file at whitespace. Is this really what you want?
boost::regex searchExpression(userDesignation); boost::match_results<std::vector<std::string>::iterator > result;
boost::regex_match(data.begin(), data.end(), result, searchExpression);
[/code]
The error is
error C2664: 'char boost::w32_regex_traits<charT>::translate(charT,bool) const' : cannot convert parameter 1 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'char'
error C2664: 'char boost::w32_regex_traits<charT>::translate(charT,bool) const' : cannot convert parameter 1 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'char'
I think the error cause by vector string iterator rather than string iterator.
Any workaround solution to this problem ?
If you really need to have vector<string> instead of just string, then you need to run regex_search in a loop: BOOST_FOREACH(const std::string& s, data) { boost::regex_match(s, result, search_expression); } In Christ, Steven Watanabe