search

Home  >  Q&A  >  body text

正则表达式 - 为何如下正则代码在VC++ 调试模式下crash

为何如下正则代码在VC++ 2013 调试模式下crash,而Release模式可以正常运行

#include <regex>
#include <iostream>
int main(){
    auto P = std::regex(R"(^([^\x00]*?)$)");
    std::smatch M;
    if (std::regex_search(std::string("A"), M, P)){
        std::cout << M[0].str();
    }
    return 0;
}
大家讲道理大家讲道理2774 days ago444

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 13:46:33

    Tested it. . No problem

    However, there is a small problem under VS2015. Directly passing std::string("A") into the regex_search function will prompt an error. The reason should be that what needs to be received here is a reference, and the constructor is deleted after passing the value.

    reply
    0
  • Cancelreply