0

I have some lines

wstring const html = LR"(

<td><a href="4.%20Functions,%20scope.ppt">4. Functions, scope.ppt</a></td>
<td><a href="4.%20Functions,%20scope.ppt">4. Functions, scope.ppt</a></td>
<td><a href="4.%20Functions,%20scope.ppt">4. Functions, scope.ppt</a></td>
)";

// for convenience
const auto fast_n_loose = regex_constants::optimize | regex_constants::icase;
//icase: without case
//optimize: priority matching efficient


// extract href's
wregex const link{ LR"~(href=(["'])(.*?)\1)~", fast_n_loose };

int main()
{
    // regex iterators       
    string s (html.begin(), html.end());
    wsregex_iterator itr_end;
    wsregex_iterator itr{ begin(html), end(html), link };
    // iterate through the matches
    for (; itr != itr_end; itr++)
    {
        wcout << itr->str(2) << '\n';
    }
}

I try to convert wstring to string but make many mistakes. Maybe I'm wrong with some structures with iterators. How can I edit?

  • Why not use `std::wstring` throughout your application? What is the reason for converting to `std::string`? – PaulMcKenzie Dec 22 '17 at 02:50
  • In fact I usually use `string`, seldom use `wstring` – BUI CHAU Minh Tung Dec 22 '17 at 02:53
  • From your code, it would seem easier to convert that 1 line `string s (html.begin(), html,end());` and make that `wstring`. Everything else in your code uses `wstring`. – PaulMcKenzie Dec 22 '17 at 02:57
  • Just remove all the `w`'s from the start of the type names. And remove all the `L`'s from in front of the string literals. – Galik Dec 22 '17 at 03:23
  • You have already asked similar questions [here](https://stackoverflow.com/questions/47928783/c-use-regex-to-find-substring) and [here](https://stackoverflow.com/questions/47901005/convert-wchar-to-lpctstr). You may want to read the answers and visit this link: https://www.joelonsoftware.com/2003/10/08/ – Barmak Shemirani Dec 22 '17 at 07:21

0 Answers0