hi,
My program created an object array containing 271 objects from the "names.txt", and each object has 3 private class variables, "id lastname and firstname "...... i know i can't use ofstream writer to write it to a new file like.... Name name; writer<<name[270];
Anyone please help me understanding how to write each private variable from the object to a new txt document.
I was wondering if i should write 3 of the "get" functions to to the variable out from the object... but since 2 variables are string class.... i don't know how to do it.
Thank you
class Name
{
public:
set(int, string, string);
private
int id;
string lastName, firstName;
}
int main()
{
Name name[300];
ifstream reader;
reader.open("names.txt");
int id, count=0;
string lname, fname;
while (reader>>id>>lname>>fname)
{
name[count].set(id, lname, fname);
count++;
}
ofstream writer;
writer.open("new.txt");
for(int x=0; x<count; x++)
{
writer<<name[x]; //i know this isn't correct,, just to show what i m trying to do
}
return 0;
}
Name::set(int inId, string inLastName, string inFirstName)
{
id= inID;
lastName = inLastName;
firstName = inFirstName;
}