我怎样才能在同一行中制作它?
看起来像:
You see a closed door.
It belongs to house 'Magician's Alley
5a'.
Nobody owns this house.
但我希望它看起来像:
You see a closed door. It belongs to house 'Magician's Alley 5a'. Nobody owns this house.
代码:
void House::updateDoorDescription()
{
std::stringstream houseDescription;
houseDescription << "It belongs to house '" << houseName << "'. " << std::endl;
if(houseOwner != 0){
houseDescription << houseOwnerName;
}
else{
houseDescription << "Nobody";
}
houseDescription << " owns this house." << std::endl;
HouseDoorList::iterator it;
for(it = doorList.begin(); it != doorList.end(); ++it){
(*it)->setSpecialDescription(houseDescription.str());
}
}
答案 0 :(得分:4)
因为你正在做
<< std::endl
这是endline
并设置了一个换行符。删除这些,它将是你想要的。