能把我急死。爲什麼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;