#include
#include
#include
using namespace std;
int main()
{
//bool same_vec(vector
int S; //create a variable for cin
vector
cout << "Please input vector A, and ended by a character" << endl; // give a hint to stop reading
while (cin >> S) // give value to variable
A.push_back(S);
sort(A.begin(), A.end());
A.erase(unique(A.begin(), A.end()), A.end()); //delete the repeated elements
cin.clear(); // clear for a new loop.
cin.ignore();
sort(A.begin(), A.end());
cout << "Please input vector B, and ended by a character" << endl;
while (cin >> S)
B.push_back(S);
sort(B.begin(), B.end());
B.erase(unique(B.begin(), B.end()), B.end());
cin.clear(); // same as vector A.
cin.ignore();
if (A == B) // Test two vectors.
cout << "vector A,B are identical";
else
cout << "vector A,B are not identical";
cin.get();
cin.get();
return 0;
}
你的习惯不好,要注意使用{},你的while循环都出了这个问题,你多写了“;”,如果使用{}就不太可能这样,然后就是底下少了一句:cin.ignore();为了看到结果,我增加了
cin.get();
cin.get();