hi, i have this code:
#include <iostream>
#include <fstream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int main (char argc)
{
for(;;)
{
fstream myfile;
myfile.open("example.txt");
cout << "1: Write" << endl;
cout << "2: Read" << endl;
int n1;
cin >> n1;
if(n1 == 1)
{
string n2;
getline(cin,n2);
myfile << n2 << endl;
}
if(n1 == 2)
{
string n3;
getline(myfile,n3);
cout << n3 << endl;
}
myfile.close();
}
}
when i run it, i want to write to the file but when i press 1, the program just goes back to the main menu. any solutions?