初学者
菜鸟求助
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector <int> x,y;
int e;
cout < < "Input x elements: " < < endl;
while (cin > > e)
x.push_back(e);
cout < < "Input y elements: " < < endl;
while (cin > > e)
y.push_back(e);
system ( "PAUSE ");
}
当输入完X按Ctrl+Z,出现Input y elements: 就结束了.
怎么不能输入Y对象呢?
------解决方案--------------------
又是输入流的问题。
------解决方案--------------------
==================================
cout < < "Input y elements: " < < endl;
cin.clear();
cin.sync();
while (cin > > e) y.push_back(e);
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector <int> x,y;
int e;
cout < < "Input x elements: " < < endl;
while (cin > > e)
x.push_back(e);
cout < < "Input y elements: " < < endl;
while (cin > > e)
y.push_back(e);
system ( "PAUSE ");
}
当输入完X按Ctrl+Z,出现Input y elements: 就结束了.
怎么不能输入Y对象呢?
------解决方案--------------------
又是输入流的问题。
------解决方案--------------------
==================================
cout < < "Input y elements: " < < endl;
cin.clear();
cin.sync();
while (cin > > e) y.push_back(e);