ex6_02.cpp

来自「Visual C++ 2005的源代码」· C++ 代码 · 共 31 行

CPP
31
字号
// Ex6_04.cpp  Using exception handling
#include <iostream>
using std::cout;
using std::endl;

int main(void)
{
  int counts[] = {34, 54, 0, 27, 0, 10, 0};
  int time = 60;                       // One hour in minutes

  for(int i = 0 ; i < sizeof counts/sizeof counts[0] ; i++)
    try
    {
      cout << endl
           << "Hour " << i+1;

      if(counts[i] == 0)
        throw "Zero count - calculation not possible.";

      cout << " minutes per item: "
           << static_cast<double>(time)/counts[i];
    }
    catch(const char aMessage[])
    {
      cout << endl
           << aMessage
           << endl;
    }
  return 0;
}

⌨️ 快捷键说明

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