作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
如何让它在同一行?
看起来像:
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());
}
}
最佳答案
因为你在做
<< std::endl
这是 endline
并放置一个换行符。去掉这些,它就是你想要的。
关于c++ - 为什么我会换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5133034/
我是一名优秀的程序员,十分优秀!