今天我在我的应用程序中遇到了奇怪的错误。我测试了2个小时,没有找到解决方案。也许你可以帮助我解决这个问题。所以这里是:
Today I encountered strange bug in my application. I've tested it for like 2 hours and didn't find a solution. Maybe you can help me solving this problem. So here it is:
#include <iostream> #include <regex> #include <vector> int main() { std::regex reg("rmvb|avi|rm|mp4|256"); std::vector<std::string> ext{"rmvb", "avi", "rm", "mp4", "256", "null"}; for (int i = 0; i < 6; i++) { std::cout << ext[i] << "\t" << std::boolalpha << std::regex_match(ext[i], reg) << std::endl; } return 0; }输出:
rmvb true avi true rm false mp4 false 256 false null false似乎模式被丢弃后的第二个元素 - 无论我选择什么顺序(我试图交换他们,可以导致这个bug - 但他们不是)。现在我不知道发生了什么。
It seems that pattern is discarded after the second element - no matter what order I choose (I tried to swap them, because I thought that digits can cause this bug - but they aren't). Now I have no idea what's going on.
我使用gcc 4.6.3版本(Debian 4.6.3-1)。
I'm using gcc version 4.6.3 (Debian 4.6.3-1).
推荐答案regex库大多数还没有在libstc ++中实现(cf. 状态页)。这可能是一个错误或只是其未实现的结果。建议您使用 Boost.Regex 作为替代品。
The regex library is mostly not yet implemented in libstc++ (cf. status page). This may be a bug or just the result of it not being implemented. I'd suggest using Boost.Regex as a replacement.
更多推荐
奇怪的bug
发布评论