Okay here's my problem the program compile but when i select option 1 it gives me the fatal error message, when i select option 2 it just closes and i dont see anything. What is wrong here? I tried both read and write functions as sepparate programs and they work fine? Whats going on? Any help would be appreciated. Thanks
float close;
char user_name[25];
char user_age[4];
int age;
cout << "Opening file for reading...\n";
ifstream infile;
infile.open("NAME_AGE.txt",ios::in);
if (infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_age,2);
infile.ignore(80,'\n');
age = atoi(user_age);
cout << "The name read from the file is " << user_name << '\n';
cout << "The age read from the file is " << user_age << '\n';
infile.close();
cin.get();
cin.get();
}
else
{
cout << "Error opening file for reading.\n";
cin.get();
cin.get();
}
}
void write()
{
float close;
char user_name[50];
char age[50];
ofstream outfile;
cout << "Enter data to be written: ";
cin.get(user_name, 50);
cout << "Enter your age: ";
cin.get (age, 50);
cin.get();
cin.get();