我写了一个程序,它基本上要求用户输入两个向量的元素。然后它比较这些向量,但程序忽略我的第二个输入流。但是,控制台不会打印错误,只会跳过第二个输入。
#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;
}
}
答案 0 :(得分:0)
来自&#34;控制台不会输出错误&#34; (假设没有打印任何东西),并且&#34;跳过第二个输入流&#34;,我想知道你是否要终止程序而不是提供正确的EOF流(通过按Ctrl + D)继续前进到第二个输入流。