运行线路后我得到随机数convert >> quarter
,我想我必须在运行它之前清除 stringstream 以再次转换,但我该怎么做呢?有人可以解释一下发生了什么:(我发现这是一个解决方案,但不太明白)
stringstream convert(tokens[1]);
convert >> quarter;
-
Play parse(string toParse){
vector<string> tokens;
string play = toParse;
string oName, dName;
int x, quarter, minutes, down, yardstogo, startloc, playdesc;
for(int y=0; y<10; y++){
x = toParse.find(",");
tokens.push_back(toParse.substr(0,x));
toParse = toParse.substr(x+1);
}
stringstream convert(tokens[1]);
convert >> quarter;
convert.str(tokens[2]);
convert >> minutes;
convert.str(tokens[6]);
convert >> down;
convert.str(tokens[7]);
convert >> yardstogo;
convert.str(tokens[8]);
convert >> startloc;
playdesc = findPlay(tokens[9]);
Play a(quarter, minutes, tokens[4], tokens[5], down, yardstogo, startloc, playdesc, play);
return a;
}
谢谢你。