我为什么要换线?

时间:2011-02-27 11:47:38

标签: c++

我怎样才能在同一行中制作它?

看起来像:

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());
}
}

1 个答案:

答案 0 :(得分:4)

因为你正在做

<< std::endl

这是endline并设置了一个换行符。删除这些,它将是你想要的。