I have bin reading thou the tutorials and making this program to help my learning but recently I have tried to output name to a TXT file and after i added ofstream a_file ( "name.txt" ); and
a_file<< string <<""; to main() it wont compile. here is my code:
im a total noob to C++ so I'm most likely making a making a stupid mistake.Code:#include <iostream>
#include <fstream>
void inerface1()
{
cout<<"__________________________________________________________________\n";
cout<<"| _______________ |\n";
cout<<"| | | |\n";
cout<<"| | input password| |\n";
cout<<"| | to continue | |\n";
cout<<"| |_______________| |\n";
cout<<"| |\n";
cout<<"|_________________________________________________________________|\n";
}
void haltpro() //handles errors
{
system("clear");
cout<<"__________________________________________________________________\n";
cout<<"| _______________ |\n";
cout<<"| | | |\n";
cout<<"| | error: | |\n";
cout<<"| | terminating | |\n";
cout<<"| |_______________| |\n";
cout<<"| |\n";
cout<<"|_________________________________________________________________|\n";
cin.get();
}
void menu()
{
system("clear");
cout<<"__________________________________________________________________\n";
cout<<"|1. input and store age |\n";
cout<<"|2. read age |\n";
cout<<"|3. store name |\n";
cout<<"|4. read name |\n";
cout<<"|5. store phone number |\n";
cout<<"|6. read phone number |\n";
cout<<"|_________________________________________________________________|\n";
}
void startornot()
{
int a;
cin>>a;
if (a == 9999)
{
menu();
}
else
{
haltpro();
}
}
void storename()
{
system("clear");
cout<<"__________________________________________________________________\n";
cout<<"| ____________ |\n";
cout<<"| | | |\n";
cout<<"| | input name | |\n";
cout<<"| |____________| |\n";
cout<<"| |\n";
cout<<"| |\n";
cout<<"|_________________________________________________________________|\n";
cout<<"name:";
}
void storephone()
{
system("clear");
cout<<"__________________________________________________________________\n";
cout<<"| ____________ |\n";
cout<<"| | | |\n";
cout<<"| |input phone#| |\n";
cout<<"| |____________| |\n";
cout<<"| |\n";
cout<<"| |\n";
cout<<"|_________________________________________________________________|\n";
cout<<"phone #:";
}
void storeage()
{
system("clear");
cout<<"__________________________________________________________________\n";
cout<<"| ____________ |\n";
cout<<"| | | |\n";
cout<<"| | input age | |\n";
cout<<"| |____________| |\n";
cout<<"| |\n";
cout<<"| |\n";
cout<<"|_________________________________________________________________|\n";
cout<<"age:";
}
int main()
{
system("clear");
inerface1();
startornot();
int z;
z = 1;
for(;;) {
int b;
cin>>b;
switch( b ) //desides on menu functions
{
case 1:
storeage();
int age;
cin>>age;
menu();
break;
case 2:
system("clear");
cout<<"__________________________________________________________________\n";
cout<<"| _____________ |\n";
cout<<"| | | |\n";
cout<<"| | inputed age | |\n";
cout<<"| | "<< age <<"\n";
cout<<"| |_____________| |\n";
cout<<"| |\n";
cout<<"|_________________________________________________________________|\n";
cout<<"press 9 to return:";
cin.get();
break;
case 3:
storename();
char string[50];
cin>> string, 50, '\n';
ofstream a_file ( "name.txt" );
a_file<< string <<"";
menu();
break;
case 4:
system("clear");
cout<<"__________________________________________________________________\n";
cout<<"| _____________ |\n";
cout<<"| | | |\n";
cout<<"| | stored name | |\n";
cout<<"| |"<< string <<"\n";
cout<<"| |_____________| |\n";
cout<<"| |\n";
cout<<"|_________________________________________________________________|\n";
cout<<"press 9 to return:";
cin.get();
break;
case 5:
storephone();
int phone;
cin>> phone;
menu();
break;
case 6:
system("clear");
cout<<"__________________________________________________________________\n";
cout<<"| ______________ |\n";
cout<<"| | | |\n";
cout<<"| |inputed phone#| |\n";
cout<<"| | "<< phone <<"\n";
cout<<"| |______________| |\n";
cout<<"| |\n";
cout<<"|_________________________________________________________________|\n";
cout<<"press 9 to return:";
cin.get();
break;
case 9:
menu();
break;
default:
menu();
break;
}
}
}