C++

C++,第1张

C++ 报错

在使用C++中的regex(正则表达式)时,发现编译能过,但是在运行到这块代码的时候,报下列错误,。

terminate called after throwing an instance of 'std::regex_error'
  what():  regex_error
Aborted
解决方案: 1. 确定gcc版本

gcc版本在4.9+才支持正则表达式。

2. 确定添加了头文件
#include 
测试代码
#include 
#include 
#include 
using namespace std;

int main()
{
	string line = "GET /404.html HTTP/1.1";
	std::regex patten("^([^ ]*) ([^ ]*) HTTP/([^ ]*)$);
	std::smatch subMatch;
	if(regex_match(line,subMatch,patten)){
		cout << subMatch[1] << endl;									// GET
		cout << subMatch[2] << endl;									// /404.html
		cout << subMatch[3] << endl;									// 1.1
	}
	return 0;
}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5115553.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-17
下一篇2022-11-17

发表评论

登录后才能评论

评论列表(0条)

    保存