【发布时间】:2017-07-18 11:24:34
【问题描述】:
假设我必须阅读以下输入:
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay
str1 str2
atcay
ittenkay
oopslay
所以我无法单独存储所有字符串。 这是我能想到的部分代码。
while(1)
{
getline(cin,s);
if(s.empty())
break;
else
cout<<s<<endl;
}
所以现在我可以将“dog ogday”存储在一个字符串中。但我想将它们存储在单独的字符串中。请帮忙。(在此先感谢:D)
【问题讨论】:
-
你听说过
>>吗?您通常会在到达getline之前了解它。
标签: c++ string input cin getline