2011-02-27 149 views
2

我怎樣才能使它在同一行?爲什麼我得到linebreaks?

它看起來像:

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

'endl'代表「end line」 – nico 2011-02-27 11:52:01

回答

4

因爲你正在做

<< std::endl 

這是endline並提出換行符。刪除這些,這將是你想要的。