C++用正则表达式,以及十六进制字符串转十进制数字的问题。

能把我急死。为什么qt里面用起来那么方便的东西回到C++感觉好复杂的样子

	const std:: regex hexPattern("^[0-9a-fA-F]{6}$");//定义六进制颜色的正则表达式
	std::smatch hexMatch; 
	std::string hex_color = strings[code.StrTranslate(code.SplitCode(code_line,1))];
	if(! std::regex_match (hex_color, hexPattern ))
	{
		cout<<"16进制颜色格式错误,请输入形如FF8000的六位16进制数(不区分大小写)!"<<endl;
		error_message.push_back("16进制颜色格式错误,请输入形如FF8000的六位16进制数(不区分大小写)!");
		hex_color = "FF8000";
	}
	//cout<<hex_color;
	int color[3];
	char * str;
	//cout<<hex_color[0];
	for(int i=0; i<5; i+=2)
	{		
		std::string temp ="0x"+hex_color.substr(i,2);		
		//cout<<temp<<endl;
		color[i/2]  = (int)strtol(temp.c_str(), &str, 16);
	}
	//cout<<color[0]<<endl<<color[1]<<endl<<color[2]<<endl;

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值