Yurttas/PL/OOL/Cplusplus/F/02/06/00/e 08.cpp

From ZCubes Wiki
Jump to navigation Jump to search
 1/* Copyright(C) 2000
 2   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 3
 4   Permission to use, copy, modify, and distribute this
 5   software and its documentation for EDUCATIONAL purposes
 6   and without fee is hereby granted provided that this
 7   copyright notice appears in all copies.
 8
 9   date   : January 1, 2000.
10   author : Salih Yurttas.
11
12   e_08.cpp
13*/
14
15
16#include <iostream>
17
18#include <string>
19
20#include <stdexcept>
21
22using namespace std;
23
24int main(int argc, char* argv[]) {
25
26  string t("tiger");
27  int index;
28
29  cout << "Enter an index: " ;
30  cin >> index;
31
32  try {
33    cout << "Char at position " << index << " is  " << t.at(index) << endl;
34  }
35  catch(out_of_range e) {
36    cout << "Error : Index value for string out of range " << endl;
37    cout << e.what() << endl;
38  }
39
40}