gpt4 book ai didi

c++ - istream& getline (istream& is, string& str);可以用于具有 '\n' 的数据吗?

转载 作者:行者123 更新时间:2023-11-30 02:52:59 25 4
gpt4 key购买 nike

istream& getline (istream& is, string& str); 此处 str 在换行符后终止。但是,如果我想处理 str cotents 2-3 行的情况,那么还有什么选择呢?

最佳答案

你可以给一个消息告诉用户终止输入,例如

std::cout<<"Enter your message (enter finish. to terminate input)"<<endl;
while (mess != "finish.")
{
std::getline(std::cin, mess);
input_message += mess;

}

希望这会有所帮助,因为它更加动态

关于c++ - istream& getline (istream& is, string& str);可以用于具有 '\n' 的数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18395521/

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