C++ examples for STL:vector
Determine if one vector is less than vector with lexicographical compare.
#include <iostream> #include <vector> using namespace std; void show(const char *msg, vector<char> vect); int main() {//from ww w . j a va 2 s . c o m // Declare an empty vector that can hold char objects. vector<char> v; // Declare an iterator to a vector<char>. vector<char>::iterator itr; // Obtain an iterator to the start of v. itr = v.begin(); // Declare a reverse iterator. vector<char>::reverse_iterator ritr; // Create another vector that is the same as the first. vector<char> v2(v); show("The contents of v2: ",v2); cout << "\n"; // Insert more characters into v and v2 at the end. cout << "Insert more characters into v and v2.\n"; v.insert(v.end(), 'D'); v.insert(v.end(), 'E'); v2.insert(v2.end(), 'X'); if(v < v2) cout << "v is less than v2.\n\n"; return 0; } void show(const char *msg, vector<char> vect) { vector<char>::iterator itr; cout << msg; for(itr=vect.begin(); itr != vect.end(); ++itr) cout << *itr << " "; cout << "\n"; }