株式会社エス・スリー・フォー

4.1 例

ここで大切なことは、RWDate により通常使用する暦の日付を素早く簡単に操作できるということです。次に、このクラスがどれくらいうまく動作するかを以下の例に示します。

ENIAC (世界最初の電子計算機) が最初に起動した日付 (1945年2月14日) を表示し、次にその前の日曜日の日付をグローバル地域を使って計算し表示します。

#include <rw/rwdate.h>
#include <rw/rstream.h>

int main(){
  // ENIAC が起動した日付
  RWDate d(14, "February", 1945);

  // 今日
  RWDate today;

  cout << d.asString("%A, %B %d 19%y")
       << " was the day the ENIAC computer was" << endl
       << "first turned on.  "
       << today - d << " days have gone by since then. " << endl;

  return 0;
}

出力:

Wednesday February 14, 1945 was the day the ENIAC computer was
first turned on. 18636 days have gone by since then.

この計算では、いつこのプログラムを実行するかによって出力される経過日数が異なります。