gpt4 book ai didi

c++ - 为什么我会换行?

转载 作者:搜寻专家 更新时间:2023-10-31 01:20:13 24 4
gpt4 key购买 nike

如何让它在同一行?

看起来像:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com