I am creating a program for my dad, which will have a catalogue of patients, and will check them for dates and such, but that's off topic. Here's my dilemma, whenever I cout a series of messages, the program will not append the message to the one before it. Instead, it simply writes over the last one. Kinda like if it's just gluing the messages on top of each other.

when I run my program:

Code:
#include <fstream>

#include <iostream>

#include <ctime>

#include <string>

#include <vector>

#include <sstream>

#include <exception>



using namespace std;



class patient     //this class will only be used by database and no direct contact with the user without database should occur

  {

private:

    string firstname;

    string lastname;

    vector<string> middlenames;

    time_t date;

public:

    patient(string fileline);//this constuctor takes a line from the database to create a patient

    string getdate();

    string getinfohuman();//I will customize this function

    string getinfocomp();

  };



patient::patient(string fileline)//be wary of the throw at the ending

  {

    try

      {

        stringstream filelinestream;

        filelinestream<<fileline;

        string currentword;

        if(true)//this if exists so the objects are deleted once the check is over

          {

            stringstream checkstream;

            string checkword;

            checkstream<<fileline;

            checkstream>>checkword;

            checkstream>>checkword;

            for (int a=30;; a--)

              {

                checkstream>>checkword;

                if (checkword=="^")

                    break;

                if (a==0)

                    throw 1;

              }

            int checkdate;

            if (!(checkstream>>checkdate))

                throw 1;

          }

        filelinestream>>currentword;

        firstname=currentword;

        filelinestream>>currentword;

        lastname=currentword;

        filelinestream>>currentword;

        for(register int middlenum=0;currentword != "^";middlenum++)

          {

            middlenames.push_back(currentword);

            filelinestream>>currentword;

          }

        filelinestream>>date;

      }

    catch (int a)

      {

        cout<<"Error creating patient"<<endl;

        throw 1;

      }

  }



string patient::getinfocomp()

  {

    string outstring;

    outstring = " " + firstname + " " + lastname;

    for (int middlenum=middlenames.size()-1; middlenum>=0; middlenum++)

      {

        outstring = outstring + " " + middlenames[middlenum];

      }

    outstring = outstring + " ^" + " " + getdate();

  }



string patient::getinfohuman()

  {

    string outstring;

    outstring = firstname + "  " + lastname + "  " + "date:" + " " + getdate();

    return outstring;

  }



string patient::getdate()

  {

    stringstream datestream;

    string outstring;

    datestream<<date;

    datestream>>outstring;

    return outstring;

  }



class database

  {

public:

    fstream &datafilestream;

    vector<patient> data;

    database(fstream &main);

    //string getinfocomp();

    //string getinfohuman();

    //void addpatient;

  };



/*string database::getinfohuman()

  {

    string outstring;

    ou

  }*/



database::database(fstream &main)//find a way to store broken patients

    :datafilestream(main)

  {

    string patientinput;  

    while(getline(main,patientinput))

      {

        cout<<patientinput<<endl;

        if(patientinput=="^eof^")

            break;

        try

          {

            patient *space=new patient(patientinput);

            data.push_back(patient(*space));

          }

        catch(int a)//this one handles the patient exeption thrown at the end of the constructor

          {

            string printme=patientinput;

            cout<<"patient "<<"\""<<printme<<"\""<<" has been discarded."<<endl;

          }

      }

  };



int main()

  {

    fstream mainfile;

    mainfile.open ("database.txt");

    database maindatabase(mainfile);

    return 0;

  }
...with database.txt being...
Code:
I'm blue badabedad I if I was green I would die bada bedadadodo ^ yougio
Dakota Camron Harrison-Smith ^ 1576800000
Foo Bar Baz ^ 0
I get

Code:
I'm blue badabedad I if I was green I would die bada bedadadodo ^ yougio
Error creating patient
" has been discarded.abedad I if I was green I would die bada bedadadodo ^ yougio
Dakota Camron Harrison-Smith ^ 1576800000
Foo Bar Baz ^ 0
in my console

I think the problem is somewhere in database:atabase(fstream &main) in the catch statement.

Anything would be helpful, even program critiques.