我想把tourist 的数据以循环的方式加到bus里,我用的是map,由于不知道具体有多少人,所以不知道怎么样控制循。我本想如果name 没有长度,那就是没有数据,就可以out of loop,但是它就进入了死循环,因为在tourist的实例里,就一直有最后的数据。请教大家应该如何处理。
class Tourist{
public:
string name;
short isSmoking;
public:
Tourist(){}
};
class Bus{
public:
map<string, short> tourists;
public:
Bus(){};
void insertValue(Tourist t){
while (true) {
if(t.name != " "){
break;
}else{
this->tourists.insert({t.name, t.isSmoking});
}
}
}
};
void Insert(const Tourist &val){if(val.name.empty()) return; tourists[key]=value;}