philRG

Sample code C++ for Thyl

Apr 12th, 2021 (edited)
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <stdexcept>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     vector<int> test;
  9.  
  10.     test.push_back(1);
  11.     test.push_back(2);
  12.     test.push_back(3);
  13.  
  14.     cout << test[0] << endl;
  15.     cout << test[1] << endl;
  16.     cout << test[2] << endl;
  17.  
  18.     cout << test.at(3) << endl;
  19.     cout << test[3] << endl;
  20.  
  21.     try {
  22.         cout << test.at(3) << endl;
  23.     }
  24.     catch (const exception &e) {
  25.         cout << "Out of range hein tu veux un dessin ??!!!" << endl;
  26.         cout << "Ton tableau ne comporte que " << test.size() << " élements!" << endl;
  27.         cout << e.what() << endl;
  28.     }
  29.  
  30.     return 0;
  31. }
Add Comment
Please, Sign In to add comment