/** @file sample for output of newlines
 *
 * This is especially relevant if a text file is written on a MS Windows
 * system which is dedicated to be processed on a *ix system.
 *
 * Last CVS checkin:
 * $Date: $
 * $Author: scheff $
 */

/**************************************************************************/

// standard C/C++ header:
#include <fstream>
#include <iostream>
#include <string>

/**************************************************************************/

using namespace std;

/** waits for user confirm.
 *
 * @param action text with next action
 */
static void pause(const char *action)
{
  cerr << "Press [ENTER] to " << action << ": " << flush;
  string str; getline(cin, str);
}

/** provides the main function of application.
 *
 * @param argc number of command line arguments
 * @param argv pointer to array of pointers to strings with command line
 *        arguments
 * @return 0 ... application exited regularly\n
 *         else ... execution of application aborted
 */
int main(int argc, char *argv[])
{
  pause("start");
  cout << "cout << endl:" << endl;
  cout << "cout << \"\\n\":\n";
  cout << "cout.put('\\n'):"; cout.put('\n');
  cout << "cout.write():"; char c = '\n'; cout.write(&c, sizeof c);
  pause("write file 'test'");
  { ofstream fout("test");
    fout << "fout << endl:" << endl;
    fout << "fout << \"\\n\":\n";
    fout << "fout.put('\\n'):"; fout.put('\n');
    fout << "fout.write():"; char c = '\n'; fout.write(&c, sizeof c);
  }
  pause("write file 'test-bin'");
  { ofstream fout("test-bin", ios::out | ios::binary);
    fout << "fout << endl:" << endl;
    fout << "fout << \"\\n\":\n";
    fout << "fout.put('\\n'):"; fout.put('\n');
    fout << "fout.write():"; char c = '\n'; fout.write(&c, sizeof c);
  }
  // done
  pause("finish");
  return 0;
}

