Transfer information from class to file

Hello , I am a newbie here. I have this assignment. I have to transfer information entered into a class to a file whose name has to be specified by the user. The first name should go to a file ,and the second name should go to another file and then a third file will display both the information. I am able to get the information in the class but not able to transfer. Any help is highly appreciated.

#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
#include<cstdlib>
using namespace std;
class N
{
private:
string name;

public:
N();

void setname(string info_name);

string getname();

//void setLname(string info_lastName);

//string getLname();
void displayName();
~N();

};

class F
{
private :
string input;
string output;
string input_output;
public:
F();
F(string name);
~F();
void setIn(string info_input);
string getIn();
void setOu(string info_output);
string getOu();
void setIO(string info_inputOutput);
string getIO();
};



int main()
{
N object_first;
N object_last;
string name;
char response;
object_first.setname(name) ;
object_last.setname(name);
cout<<endl<<endl;
object_first.displayName();
cout << " \t " ;
object_last.displayName();

cout << endl<<endl<<endl<<endl;

cout << " Do you want to enter your information in a file ? " <<endl<<endl;
cin>>response;
cout<<endl;



if (response == 'y')
{

//F object1,object2;

const int max = 80;

ofstream outFile("first.txt");
if(!outFile)
{
cerr << "Open failed\n";
exit(1);
}


char buffer[max];
while(!cin.getline(buffer, max).eof())
{
outFile << object_first.getname() ;
cout<<endl<<endl;
}


cout << " DO you want to enter the information for the last name in to a file ? " <<endl;
cin>>response;

if (response == 'y')
{


cout << " Enter a name of a file for the last name : " ;
cin>>name;
const int max2 = 80;

ofstream outfile(name);
if(!outfile)
{
cerr << "Open failed\n";
exit(1);
}



char buffer1[max2];
while(!cin.getline(buffer1, max2).eof())
{
outfile << object_last.getname() ;
cout<<endl<<endl;
}



}




else if(response == 'n')
{
cout << " Program terminated"<<endl<<endl;
}
else
{
cout << " Invalid entry. Program terminated."<<endl<<endl;
}







}
return EXIT_SUCCESS;
}

N :: N()
{
cout << " Object created in the constructor "<<endl<<endl;
name = " " ;

}
N :: ~N()
{
cout << " Object destroyed " <<endl<<endl;
}

void N :: setname (string info_name)
{
cout << " Please enter your first name : " ;
cin >> info_name;
name = info_name;
}



string N :: getname()
{
return name;
}




void N :: displayName()
{
cout << getname() ;
}

F :: F (string name)
{
name = input;
}
Topic archived. No new replies allowed.