Tokenise line from file into vector with the following and am trying to copy vector values to variables - have tried EVERYTHING c_str()
And have NO idea what is happening. Have noted all that have tried in below code. Any ideas??? The error msg is:
cannot convert std::string to char* strcpy(char*,const char*)
Code:
void Tokenize(const string& str,
vector<string>& tokens,
const string& delimiters = "/n")
{
// Skip delimiters at beginning.
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
string::size_type pos = str.find_first_of(delimiters, lastPos);
while (string::npos != pos || string::npos != lastPos)
{
// Found a token, add it to the vector.
tokens.push_back(str.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = str.find_first_of(delimiters, lastPos);
}
}
void loadTeams(char *line,string countryName,string code)
{
string temp;
vector<string> teamTokens;
std::vector<string>::const_iterator p;
Tokenize(line, teamTokens,"|");
p=teamTokens.begin();
This compiles but doesnt work
Team* pTeam1 = new Team();
pTeam1->setCountry(teamTokens[0]);
pTeam1->setCountryCode(teamTokens[1]);
for(p=teamTokens.begin();p!=teamTokens.end();p++)
{
This compiles but doesnt work
countryName=p[0];
code=p[1];
This doesnt compile
strcpy(countryName,*p);
}
}