⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 safearraytester.cpp

📁 为SSD5课程《数据结构与算法》中的练习
💻 CPP
字号:
#include <stdexcept>
#include <iostream>
#include <cstdlib>

using namespace std;

#include "safearray.h"

int main (int argc, char *argv[]) {

  safearray<int> A(5);

  int index = 0;

  for (index=0; index < 5; index++) {
    A[index] = index;
  }

  for (index=0; index < 5; index++) {
    cout << A[index] << endl;
  }

  /*!Begin Snippet*/
  try {
    cout << A[-1] << endl; // attempt to read
  }
  catch (out_of_range& e) {
    cerr << e.what() << endl; // "Index is below 0"
  }

  try {
    A[100] = 1;  // attempt to write
  }
  catch (out_of_range& e) {
    cerr << e.what() << endl; // "Index is too high"
  }
  /*!End Snippet*/
  
  return EXIT_SUCCESS;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -