Rogue Wave Banner

Click on the banner to return to the user guide home page.

©Copyright 1996 Rogue Wave Software

Example

The point is that RWDate allows you to quickly and easily manipulate the calendar dates you're most likely to use. Here is an example that demonstrates the virtuosity of the class.

Let's print out the date when ENIAC first started, 14 February 1945, then calculate and print the date of the previous Sunday, using the global locale:

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

int main(){
  // ENIAC start date
  RWDate d(14, "February", 1945);

  // Today
  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;
}

Program Output:

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

In this calculation, notice that the number of days that have passed depends on when you run the program.


Previous file Table of Contents Next file