开发者

C++ Boost's sregex_token_iterator crash

开发者 https://www.devze.com 2023-02-16 21:03 出处:网络
I\'m using the following code to get the image filenames from an HTML file. The code goes somehow like this:

I'm using the following code to get the image filenames from an HTML file.

The code goes somehow like this:

std::tr1::regex term=(std::tr1::regex)r;
const std::tr1::sregex_token_iterator end;

for (std::tr1::sregex_token_iterator i(s.begin(),s.end(), term); i != end; ++i)
   {
     std::cout << *i << std::endl;
   }

s is a string that is already declared and contains the full string of the file.

r is a string that contains the regex term to look for.

This code does actually retrieve the values from the file correctly, but after reaching the last one it crashes. It might have to do with the token_iterator i, but I don'开发者_C百科t have a clue of what is causing it or how to fix it.


I don't know if you already solved the problem, but find my suggestions below:

  1. Did you try to change the ++i to i++?
  2. Did you look at the HTML file to see if the first filename that cout shows is in fact the first one in the file?

I think the first loop on cout will print the second match in the HTML file.

If you already solved it please let me know the code applied, I'm working with boost regex and it would help me on future problems that I may have.

Regards,

Tchesko.


I really forgot about this-- I'm pretty sure there was an external problem on this, linker-related, so it was kinda hard to figure out. But the code was fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消