/*----
  signature: main: void -> int
  purpose: demoing an istringstream

  by: Sharon Tuttle
  last modified: 2022-11-17
----*/

#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include <cmath>
#include "Point.h"    
using namespace std;

int main()
{
    cout << boolalpha;

    ifstream file_in;
    file_in.open("points.txt");

    istringstream input_ss;

    vector<Point> file_points;
    string next_point_string;

    double next_x;
    double next_y;

    // read point data from file to create
    //     a vector of Point objects
    
    while (getline(file_in, next_point_string))
    {
        cout << "[" << next_point_string << "]" << endl;

        // clear the previous string, if any, from
        //    the stringstream

        input_ss.clear();

        // for an istringstream, calling the str
        //   method with a string argument puts that
        //   string into the istringstream

        input_ss.str(next_point_string);

        // now I can read from the istringstream using >>

        input_ss >> next_x;
        input_ss >> next_y;

        file_points.push_back(Point(next_x, next_y));
    }

    file_in.close();

    cout << endl;
    cout << "file_points now contains: " << endl;

    for (int i=0; i < file_points.size(); i++)
    {
        cout << file_points[i].to_string() << endl;
    }

    return EXIT_SUCCESS;
}