我写了这段奇怪的小代码。这怎么可能type
在它的 2 之间发生变化printf
?
提前致谢
int main()
{
string label = string("faults_team_A_player_12");
size_t f = label.find('_');
const char *type = label.substr(0,f).c_str();
const char team = label.at(f+sizeof("team_"));
printf("type = %s\n",type);
int n;
size_t l = label.length()-label.find_last_of('_');
int x = sscanf((char *)label.substr(label.find_last_of('_'),l).c_str(),"_%d",&n);
printf("type = %s\n",type);
printf("team = %c\n",team);
printf("player = %d\n",n);
return 0;
}
输出:
type = faults
type = _12
team = A
player = 12