不能理解为何这样一个这个的代码就会报函数已删除的错误
#include <iostream>
#include <string>
#include <regex>
using namespace std;
int main()
{
regex r;
try {
r.assign("[[:alnum:]]+\\.(cpp|cxx|cc)$", regex::icase);
}catch(regex_error e)
{
cout << e.what() << "\ncode: " << e.code() << endl;
}
smatch results;
if (regex_search(string("myfile.cc"), results, r))
cout << results.str() << endl;
}
但是下面这样的代码就可以正常查找,有没有人知道原因为何?
#include <iostream>
#include <string>
#include <regex>
using namespace std;
int main()
{
regex r;
try {
r.assign("[[:alnum:]]+\\.(cpp|cxx|cc)$", regex::icase);
}catch(regex_error e)
{
cout << e.what() << "\ncode: " << e.code() << endl;
}
smatch results;
string s = "myfile.cc";
if (regex_search(s, results, r))
cout << results.str() << endl;
}