求解:第二组数无法输入
程序代码:
#include <iostream> #include <vector> using namespace std; int main() { vector<int> ivec1,ivec2; int num1,num2; cout<<"Enter the first series of numbers:"<<endl; while(cin>>num1) ivec1.push_back(num1); cout<<"Enter the second series of numbers:"<<endl; while(cin>>num2) ivec2.push_back(num2); vector<int>::iterator it=ivec1.end()<ivec2.end()?ivec1.end():ivec2.end(); for(vector<int>::iterator it1=ivec1.begin();it1!=it;++it1) for(vector<int>::iterator it2=ivec2.begin();it2!=it;++it2) { if(*it1!=*it2) {cout<<"false!"<<endl; return -1; } else{ cout<<"ture!"<<endl; if(ivec1.end()<ivec2.end()) cout<<"The first numbers are parts of second numbers"<<endl; else if(ivec1.end()==ivec2.end()) cout<<"The first numbers are equle to second numbers"<<endl; else cout<<"The second numbers are parts of first numbers"<<endl; return 0; } } }
程序的要求是输入2组数,少的一组个数为n的话,就比教两组数的前n个是否相同,是就返回true
我按要求写了这么段代码,可是在输完第一组数字后,提示输入第二组数字后,就无法再输入任何内容,过了一段时间,程序会自动结束。实在是找不到是什么问题