Code:
string parseColor(string)
{
int index1, index2, index3;
unsigned int index4;
int index5, index6,index7;
int index_Gr1,index_Gr2;
int index_R1,index_R2,index_R3,index_R4;
int index_G1,index_G2,index_G3,index_G4;
int index_B1,index_B2,index_B3,index_B4;
int index_A,index_B;
int comma1,comma2;
string space (" ");
string junk=(" "",");
string color_name;
int s_length;
string color_num1;
string colorRed,colorGreen,colorBlue;
string s,info;
index1=s.find("color");
index2=s.find_first_not_of(space,index1+5);
index3=s.find_first_of(space,index2+1);
color_name=s.substr(index2,index3-index2);
s_length=s.length();
index4=s.find("gray",index3+1);
//if color_name is gray do this:
if(index4!=string::npos){
index_Gr1=s.find_first_not_of(space,index4+4);
index_Gr2=s.find(space,index_Gr1);
color_num1=s.substr(index_Gr1,index_Gr2-index_Gr1);
info=color_name+" "+color_num1+" "+color_num1+" "+color_num1;
}
//color_name is not gray
else{
index_A=s.find_first_not_of(space,index3+1);
index_B=s.find_first_not_of(space,index_A+2);
comma1=s.find(",",index_B+1);
comma2=s.find(",",comma1+1);
I keep getting the same error message:
terminate called after throwing an instance of 'std:ut_of_range'
what(): basic_string::substr
I don't understand why if I put the exact code in main it works fine.
Please help.