/*
 * @topic T00356 May 2 -- writing to file and reading a file line-by-line
 * @brief Demonstrates <tt>ofstream ifstream open() close() getline() ios::app</tt>
*/

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
    // write into the file
    ofstream out;
    out.open( "D:/CIS155/dummy.txt", ios::out | ios::app );
    out << "four\nfive\nsix\n";
    out.close();

    // read from the file
    ifstream inp;
    inp.open( "D:/CIS155/dummy.txt" );
    string str;
    int text_length = 0;
    while( getline( inp, str ) ) {
        cout << str << '\n';
        text_length = text_length + str.length();
    }

    cout << "file length is " << text_length << '\n';
    inp.close();

    return 0;
}