I'm working on a program, that needs to load data from a text file upon starting and save data to THE SAME text file upon exit. I have the load working, and i have the save working, but for some reason I cant seem to have them both work within the same program.

This doesnt work...

```
ifstream loadfile("test.txt");
ofstream savefile("test.txt");

void load()
{
string name;

    while(!loadfile.eof())
    {
        getline(loadfile,name);
        cout<<"name " << name<<"\n";
    }
}

void save(User &name)
{   
savefile << name.getName() << endl;
}

```

Neither does this...

```
fstream file("test.txt");

void load()
{
string name;

    while(! file.eof())
    {
        getline(file,name);
        cout<<"name " << name<<"\n";
    }
}

void save(User &name)
{   
file << name.getName() << endl;
}

```

The thing is, I can save a list of names, which works fine... but as soon as i start the program, all the names from the list delete from the text file.

Also, I know that getline() gets the data from the text file as a string type, but how would i convert that to something like an int.

Thanks