Auto save & Load

Hello C++ forum. New time poster here. So he's my problem, i'm trying to learn how to make my program auto save & load. I want it to save certain things at certain points like for example right now i have it were it will save your name. An also want it to if it finds it, load your name, and go to the menu. This is what i have for code (yes i have the dreaded goto code, but that's the easiest thing i could understand for looping).


#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{

// Zero [Program]
system("CLS");
cout << "\t\t\t--=== Zero [V1.0] ===--\n\n";
cout << "I am Zero" <<endl
<< "Right now I can't do much, but my programmer is hard at work to fix that." <<endl
<< "May I start by asking your name?" <<endl<<endl;
string name;
cin >> name;
mood:
cout << "\nHello " << name << " How are you today?\n\n";
string moodchoice;
cin >> moodchoice;
if (moodchoice == "Good"||moodchoice=="good")
{
cout << "\nThat's good I'm glad! :)\n\n";
}
else if (moodchoice=="Bad"||moodchoice=="bad")
{
cout << "\nI'm so sorry. That's to bad. :(\n\n";
}
else
{
cout << "\nI didn't understand what you said. Could you please repeat yourself.\n";
cin.get();
cin.ignore();
goto mood;
}
menu:
cout << "What can I do for you today." <<endl<<endl;
cout << "::MENU::" <<endl
<< "[1] Notepad" <<endl
<< "[2] Calculator" <<endl
<< "[3] Exit" <<endl<<endl;
int choice;
cin >> choice;
switch (choice)
{
case 1:
{
cout << endl << "What do I look like a wordprocesser? [SOON TO COME]";
break;
}
case 2:
{
cout << endl << "AHAHAHAHAHAHAHA!!!.... Math.... [SOON TO COME]";
break;
}
case 3:
{
cout << endl << "Sorry to see you go, but I understand. Good luck!";
break;
}
}

// Zero [save]
ofstream myfile;
myfile.open("zero.txt");
myfile << name;
myfile.close();

cin.get();
cin.ignore();
return 0();
}


Did this all while learning C++ for the past 2 days (I know I'm still a noob.)
Last edited on
Topic archived. No new replies allowed.