C++ C++;输入流失败

C++ C++;输入流失败,c++,vector,input,C++,Vector,Input,我写了一个程序,基本上要求用户输入两个向量整数的元素。然后它比较这个向量,但是程序忽略了我的第二个输入流。但是,控制台不会打印错误,它只跳过第二个输入 #include <vector> #include <iostream> using namespace std; int main() { //Introduction cout << "This is a comparison program between two vectors of ints."

我写了一个程序,基本上要求用户输入两个向量整数的元素。然后它比较这个向量,但是程序忽略了我的第二个输入流。但是,控制台不会打印错误,它只跳过第二个输入

#include <vector>
#include <iostream>

using namespace std;

int main() {
//Introduction
cout << "This is a comparison program between two vectors of ints." << endl;

vector<int> ivec1;
vector<int> ivec2;
//First vector
int v1;
cout << "Insert the values for the first vector." << endl; 
while (cin >> v1) {
    ivec1.push_back(v1);
}
cin.clear();
//Second vector
int v2;
cout << "Insert the values for the second vector." << endl;
while (cin >> v2) {
    ivec2.push_back(v2);
}
cin.clear();
//Equal? If yes, first smaller?
if (ivec1 == ivec2) {
    cout << "Both vectors are equal." << endl;
}
else {
    if (ivec1 < ivec2)
        cout << "This two vectors are unequal and the first vector is smaller." << endl;
    else
        cout << "This two vectors are unequal and the second vector is smaller." << endl;
}
}
#包括
#包括
使用名称空间std;
int main(){
//导言

cout从“console不打印错误”(假设不打印任何内容)和“跳过第二个输入流”,我想知道您是否在终止程序而不是提供正确的EOF流(通过按Ctrl+D)转到第二个输入流。

您准备好学习如何在调试器中单步执行代码了吗?您一直在使用
cin.clear()。我不认为这意味着你认为它意味着什么。“Drduldman恐怕OP没有一点线索。但这在很多问题中都会很常见。我不想再多问了。只是DVCV:-P... DrWordMon iAm是新的C++。我不知道如何使用调试器。掌握编程语言的基本技能!大多数IDE(您可能正在使用一种IDE)都只提供了一种功能,可以在开箱即用的情况下逐步完成您的代码。我提供了EOF。第一个流是可以的,但它跳过了第二个输入流并提供了第二个向量0元素。然后比较表明第一个向量更大。