Help with output file

Hello, can someone please help me with my code? I have to take a input file that has a list of president names (last name middle name first name) and I have to output them in an output file in the format of - last name, first name. I know how to do the basics like opening the input and output file but I'm not sure on how to actually put the names into the output file and in that format. If someone could please help me? Thank You!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    int num;
    string ifilename;
    string ofilename;
    cout << endl << "Enter the inputfile name:";
    cin >>  ifilename ;
    cout << endl << "Enter the outputfile name:";
    cin >>  ofilename ;
    
   ifstream ifs;
   ofstream ofs;
   
   ifs.open(ifilename, ios::app);  
   ofs.open(ofilename);

   if(!ifs.fail() && !ofs.fail())
   {
     ifs >> num;     //need help here
     cout << num;
     ofs << num;
     cout << num;   
   }
   
   ifs.close();
   ofs.close();
   return 0;

}
Put the code you need help with here.
U can try something like as below this is not exact code but u can get some idea

char testbuf[3][3][50]={0};


ifstream fin("Test.txt");

if (fin.fail())
{
cout << "Failed" <<"endl";
return;
}


for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 3; col++)
{

fin.getline(testbuf[row][col],100,' ');


}
}
fin.close();
ofstream fout("Test1.txt",std::ofstream::binary);


for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 3; col++)
{
if(col!=2 )
fout.write(testbuf[row][col],100);


}
}

I mean first u can keep all the data in 3D array and then retrieve according to your need
Oh, okay thank you very much!
Topic archived. No new replies allowed.