//  neatColumns2.cpp
//
//  Displays table of powers of two,
//  with right-justified columns.
//  Demonstrates the setw manipulator with integers.
//  Demonstrates an output text file.

#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
   char filename[] = "powersOfTwo.txt";

   ofstream outputFile;
   outputFile.open(filename);

   if ( !outputFile )  {
      cout << "Could not create file " << filename
                << "." << endl;
      return 1;
   }  // if

   outputFile << "Powers of two" << endl;
   outputFile << "-------------" << endl << endl;
   outputFile << "Exponent     Power" << endl;
   outputFile << "--------     -----" << endl << endl;

   int power = 1;
   int exponent = 0;

   while ( power < 100000 )
   {
      outputFile << setw(5) << exponent << " "
                  << setw(11) << power << endl;
      power *= 2;
      exponent++;
   }  // while

   cout << "File " << filename
                << " has been created." << endl;

   return 0;
}  // function main