1: //vector18.cpp 3: #include <iostream> 4: #include <iomanip> 5: #include <vector> 6: using namespace std; 8: int main() 9: { 10: cout << "\nThis program illustrates the meanings of the overloaded " 11: "relational operators\nwhen used to compare vector objects. " 12: "You must enter values for two integer\nvectors, and then you " 13: "will see a display of how the first of those vectors\ncompares " 14: "to the second, using each of the relational operators."; 15: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 17: bool doItAgain; 18: do 19: { 20: cout << "\nHow many values for the first vector? "; 21: int sizeOfFirst; 22: cin >> sizeOfFirst; 23: vector<int> v1; 24: cout << "\nEnter your values for the first vector:\n"; 25: for (int i=1; i<=sizeOfFirst; i++) 26: { 27: int value; 28: cin >> value; 29: v1.push_back(value); 30: } 32: cout << "\nHow many values for the second vector? "; 33: int sizeOfSecond; 34: cin >> sizeOfSecond; 35: vector<int> v2; 36: cout << "\nEnter your values for the second vector:\n"; 37: for (int i=1; i<=sizeOfSecond; i++) 38: { 39: int value; 40: cin >> value; 41: v2.push_back(value); 42: } 44: cout << "\nHere are the contents of v1:\n"; 45: for(vector<int>::size_type i=0; i<v1.size(); i++) 46: cout << v1.at(i) << " "; 47: cout << "\nHere are the contents of v2:\n"; 48: for(vector<int>::size_type i=0; i<v2.size(); i++) 49: cout << v2.at(i) << " "; 51: cout << "\n\nAnd here are the results of the comparisons:"; 52: cout << "\nv1 == v2 is " << boolalpha << (v1==v2) << "."; 53: cout << "\nv1 != v2 is " << boolalpha << (v1!=v2) << "."; 54: cout << "\nv1 < v2 is " << boolalpha << (v1<v2) << "."; 55: cout << "\nv1 <= v2 is " << boolalpha << (v1<=v2) << "."; 56: cout << "\nv1 > v2 is " << boolalpha << (v1>v2) << "."; 57: cout << "\nv1 >= v2 is " << boolalpha << (v1>=v2) << "."; 58: cout << "\nDo it again? [y/n] "; 59: char ch; 60: cin >> ch; 61: doItAgain = (ch == 'y'); 62: } 63: while (doItAgain); 64: }