C++ 将名称读入带有空格c++;
我有一个类似这样的输入文件(东西之间有1个空格): 我尝试将其读入如下结构:C++ 将名称读入带有空格c++;,c++,C++,我有一个类似这样的输入文件(东西之间有1个空格): 我尝试将其读入如下结构: struct Contestant{ string name; int year; }; 这是游戏的另一个结构: struct Result{ string raceName; int place; }; 这就是我在下一个()函数中所做的: 这里我只想把带空格的全名读入_cur.name Contestant _cur; 看起来你应该使用getline@Eljay,真正棘手的是把
struct Contestant{
string name;
int year;
};
这是游戏的另一个结构:
struct Result{
string raceName;
int place;
};
这就是我在下一个()函数中所做的:
这里我只想把带空格的全名读入_cur.name
Contestant _cur;
看起来你应该使用
getline
@Eljay,真正棘手的是把Big John
和Jacob Rafael Ben
读入\u cur.name
同样好。
void next(){
string line;
getline(_f, line);
_end = _f.fail();
if(!_end){
istringstream is(line);
is >> _cur.name >> _cur.year;
Result tmp;
while (is >> tmp.raceName >> tmp.place){
if (tmp.place == 1){
counter++;
}
}
}
}
Contestant _cur;