Monday, 30 April 2012

Dealing with Vectors and Strings in C++


#include <iostream>
#include <vector>
#include <exception>

using namespace std;

int main( ) {

   char charcx[] = {'a', 'b', 'c', 'd', 'e'};

   cout << charcx[100000] << '\n';
                                 
   vector<char> v;
   v.pb('a');
   v.pb('b');
   v.pb('c');
   v.pb('d');
   v.pb('e');

   try {
      cout << v.at(10000) << '\n'; 
   } catch(out_of_range& e) {     
      cerr << e.what( ) << '\n';
   }
}

No comments:

Post a Comment