我正在尝试从文件中获取字符串的其余部分,以将字符串存储在变量中。例如,第一行是“ 1234 Shanghai,China”,但变量查询仅获取“ Shanghai”,而不是“ Shanghai,China”。权重为1234。我猜这与城市和乡村之间的空间有关。
while (!file.eof())
{
string query;
long weight;
file >> weight >> query;
Term inputTerm(query,weight);
}
像这样的东西:
long weight;
char query[100];
while (file >> weight)
{
file.getline(query, 100);
Term inputTerm(std::string(query), weight);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句