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;

    原文作者:进制转换
    原文地址: https://blog.csdn.net/sinat_39088557/article/details/74506164
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞