

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>

int main(void )
{
  std::ifstream InFile;
  std::string InFileName;
  char c;
  int CharCount=0, LineCount=0;

  std::cout << "Input the name of a file: " << std::endl;
  std::cin >> InFileName;
  InFile.open(InFileName.c_str());

  while (InFile.fail() )
  {
     std::cout << "Cannot open " << InFileName << " for reading." << std::endl;
     std::cout << "Enter another file name : ";
     std::cin >> InFileName;
     InFile.open(InFileName.c_str());
  }
  std::cout << "Successfully opened " << InFileName << std::endl;
  InFile.get( c );

  while( ! InFile.eof() ) {
    CharCount++;
    if (c == '\n')
       LineCount++;
    InFile.get( c );
  }
  std::cout  << InFileName << " contains "
       << CharCount << " characters and "
       << LineCount << " lines.\n";

  InFile.close();

  return(0);
}
