// L-7 MCS 360 Wed 8 Sep 2010 : open_file.cpp

/* The user is prompted for the name of an input file. 

   Unlike Python for example, no exception is generated if the name
   cannot be associated with a file at creation of a file stream.
   Likewise, reading from a file stream unassociated with a file
   does not cause an exception.

One way to enforce an exception when the association fails
is to use the assert statement.  */

#include <iostream>
#include <fstream>
#include <string>
#include <cassert>

using namespace std;

int main()
{
   string input_file_name;

   cout << "Give name of input file : ";
   cin >> input_file_name;

   cout << "Attempting to open \""
        << input_file_name << "\"..." << endl;

   ifstream ins(input_file_name.c_str());

   assert(ins);

   cout << "Opening \"" << input_file_name
        << "\" succeeded!" << endl;

   ins.close();

   return 0;
}

