#include "libscl.h"
using namespace scl;
using namespace std;

int main(int argc, char** argp, char** envp)
{

  // Illustrate multiple file open and close

  ofstream fout;

  fout.open("first.txt");
  if (!fout) error("File open failed");
  fout<<"How now brown cow.\n";
  fout.close();

  fout.clear();
  fout.open("second.txt");
  if (!fout) error("File open failed");
  fout<<"Now is the time for all good men to come to the aid of their party.\n";
  fout.close();
  
  fout.clear();
  fout.open("third.txt");
  if (!fout) error("File open failed");
  fout<<"The quick brown fox jumped over the lazy dogs.\n";
  fout.close();
  
  ifstream fin;
  string word;
  string text;

  text = "";
  fin.open("first.txt");
  if (!fin) error("File open failed");
  while(fin >> word) text += word + " ";
  cout << text << '\n';
  fin.close();

  text = "";
  fin.clear();
  fin.open("second.txt");
  if (!fin) error("File open failed");
  while(fin >> word) text += word + " ";
  cout << text << '\n';
  fin.close();
  
  text = "";
  fin.clear();
  fin.open("third.txt");
  if (!fin) error("File open failed");
  while(fin >> word) text += word + " ";
  cout << text << '\n';
  fin.close();
  
  return 0;
}
