c++连续输入多个字符串,又不知道具体多少个字符串。以Ctr+z表示文件结束。看代码
#include <iostream>
using namespace std;
int main()
{
string food;
int count = 0;
cout << "你喜欢吃什么?";
//文件结束符(Ctr + z)
while (cin >> food)
{
count++;
cout << "你最喜欢的第" << count << "美食是:" << food << endl;
cout << "你还喜欢吃什么?";
}
cout << "你最喜欢吃的美食有" << count << "种" << endl;
system("pause");
return 0;
}
运行结果如下: