1.C++读取屏幕一行的多个字符串,字符串用空格隔开
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main()
{
stack<string> str;
cout<<"Please enter some strings separated by space! Q to quit!"<<endl;
string temp;
cin>>temp;
while(temp!="Q")
{
str.push(temp);
cin>>temp;
}
while(!str.empty())
{
cout<<str.top()<<" ";
str.pop();
}
cout<<endl;
return 0;
}
测试结果: