I suggest first confirming that you are reading and writing appropriately by doing something like this:
Code:
//open first file for input of information
ifstream fin;
fin.open ("G:\\HEHP\\HVMDATALOGOUT.txt", ios::in | ios::nocreate);
if (fin.fail ())
{
return EXIT_FAILURE;
}
//open second file for input of information
ifstream fin2;
fin2.open ("G:\\HEHP\\HVMDATALOGIN.txt", ios::in | ios::nocreate);
if (fin2.fail ())
{
return EXIT_FAILURE;
}
//open stream to write information to file
ofstream fout;
fout.open ("G:\\HEHP\\HVMDATALOGOUT2.txt", ios:ut | ios::app);
if (fout.fail ())
{
cout <<"Unable to open file HVMDATALOGOUT2.txt"<<endl;
return EXIT_FAILURE;
}
//do
while (!fin.eof () && (!fin2.eof())
{
//input from first file
fin >> function;
fin >> partnerName;
fin >> partnerId;
fin >> equipType;
fin >> equipNumber;
fin >> counter;
fin.ignore ();
fin.getline (dateTime, 30);
cout<< function<<endl;
cout<< partnerName<<endl;
cout<< partnerId<<endl;
cout<< equipType<<endl;
cout<< equipNumber<<endl;
cout<< counter<<endl;
cout<< dateTime<<endl;
cout <<"*************************************"<<endl;
//input from second file
fin2 >> function2;
fin2 >> partnerName2;
fin2 >> partnerId2;
fin2 >> equipType2;
fin2 >> equipNumber2;
fin2.ignore ();
fin2.getline (dateTime2, 30);
cout <<function2<<endl;
cout <<partnerName2<<endl;
cout <<partnerId2<<endl;
cout <<equipType2<<endl;
cout <<equipNumber2<<endl;
cout <<dateTime2<<endl;
cout <<"##############################"<<endl;
//confirming what to write to file
cout<<"writing to the data2 file"<<endl;
cout <<function<<endl;
cout <<partnerName<<endl;
cout <<partnerId<<endl;
cout <<equipType<<endl;
cout <<equipNumber<<endl;
cout <<counter<<endl;
cout <<dateTime<<endl;
//actually writing to file
fout << function< <" "<<partnerName<< " "<< partnerId<<" "
<< equipType<<" "<<equipNumber<<" "<<counter<<"\n"
<< dateTime<< endl;
}
if the files being read are of the format of the file being written, then this should work fine for demonstation purposes.
Once you have proved that the call to ignore() and getline() are working as expected, then you can work out a mechanism to do what it is you want to do. To do that I strongly recommend you be able to write it out in pseudocode with pencil and paper before you write the actual code. It usually saves a lot of time and effort to do it that way.