【发布时间】:2014-11-28 18:27:48
【问题描述】:
我的代码在到达正则表达式部分时编译崩溃:
我想检查接收到的字符串中是否存在任何数字。
#include <iostream>
#include <regex>
using namespace std;
int main()
{
int in, count, rate;
char *w;
cin >> count;
for(in = 1; in < 5; in++) {
rate = 0;
cin >> w;
cout << "Case #";
cout << in;
cout << ":";
if (regex_match (std::string(w), regex("([0-9])")))
++rate;
cout << rate;
cout << endl;
}
return 0;
}
【问题讨论】:
-
那么你在哪里为
char *变量分配内存?弄清楚之后,别忘了也释放它......