At the following first line of code I get this error: cannot convert ‘std::string’ to ‘char*’ for argument ‘1’ to ‘char* strtok(char*, const char*)’
void ToToken( ) {
TokenLine.reserve(30);
char * tmp;
TokenLine[0]= strtok (Line," ");
while(tmp!=NULL)
for(int i=0;i<TokenLine.size();i++){
TokenLine[i]= strtok(NULL," ");
if(TokenLine[i]==NULL||TokenLine[i]==" ")
TokenLine.erase(i);
cout<<Token[i];
}
}
Full code:
class CombatLine{
string Line;
bool combat;
char LT[4];
time_t rawtime;
vector<string> TokenLine;
CombatLine(){
combat = false;
}
void SetLine(string S){
Line="[Combat] 03:33:05 -Anthrax- Roshi heals -Anthrax- Roshi for 2630 points of damage.";
}
bool isLineCombat(){
if(Line.substr(0,8)=="[Combat]")
return true;
else
return false;
}
bool StrFound(string SubString){
size_t tmp;
tmp = Line.find(SubString);
if(tmp!=string::npos)
return true;
else
return false;
}
void SetLT(){
LT[0]=Line.at(13);
LT[1]=Line.at(14);
LT[2]=Line.at(16);
LT[3]=Line.at(17);
}
char ReturnLT(int Index){
return LT[Index];
}
void SetType(){
if (this->StrFound("(dodge)"))
Event.SetType("dodge");
if (this->StrFound(" (parry) "))
Event.SetType("parry");
if(this->StrFound("misses"))//because we know its not a parry or dodge if we made it this far
Event.SetType("miss");
if(this->StrFound(" strikes through "))
Event.SetType("st");
if(this->StrFound("(evaded)"))
Event.SetType("evade");
if(this->StrFound("crits"))
Event.SetType("crit");
if(this->StrFound("hits"))
Event.SetType("hit");
if(this->StrFound("glances"))
Event.SetType("glance");
else
Event.SetType("not found");
}
void ToToken(){
TokenLine.reserve(30);
char * tmp;
TokenLine[0]= strtok (Line," ");
while(tmp!=NULL)
for(int i=0;i<TokenLine.size();i++){
TokenLine[i]= strtok(NULL," ");
if(TokenLine[i]==NULL||TokenLine[i]==" ")
TokenLine.erase(i);
cout<<Token[i];
}
}
string ReturnType(){
this->SetType();
return Event.ReturnType();
}
void SetMinMax(){
if(Event.ReturnType()=="miss"||Event.ReturnType()=="dodge"||Event.ReturnType()=="parry")
Event.SetMinMax(0,0);
}};
Am I passing the wrong type I string to strtok. I know I am playing with C-string and & C++ string without distinguishing them much.
Also is strtok a static method of String.h? What If I want to pass it another string to tokenize?
Thanks, Macaire Bell