Mar 27, 2013 at 6:11pm UTC
Why doesn't my newmaster.txt file have any data in it. Even when I cout << Fname[count]; after my while loop I don't get anything printed on screen. If I do cout << Fname; I get number printed on the screen. Please help. Thank you,
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
ofstream PayrollOut;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream PayrollIn;
PayrollIn.open("master.txt");
PayrollOut.open("newmaster.txt");
if(!PayrollIn || !PayrollOut)
{
cout << "Input/Output file(s) not opened\n";
cout << "Program ending\n";
exit(1);
}
string Fname[25], Lname[25], ID[25];
float Pay[25];
int Benefit[25];
int count = 0;
PayrollIn >> Fname[count] >> Lname[count] >> ID[count] >>
Pay[count] >> Benefit[count];
while(PayrollIn)
{
count++;
PayrollIn >> Fname[count] >> Lname[count] >> ID[count] >>
Pay[count] >> Benefit[count];
}
for(count=0; count < 0; count++)
{
PayrollOut << Fname[count] << Lname[count] << ID[count] <<
Pay[count] << Benefit[count];
}
system("pause");
return 0;
}
Mar 27, 2013 at 6:28pm UTC
In this loop
for(count=0; count < 0; count++)
you assign zero to count. So the loop will be executed never and you will lose the current number of entered data.
Mar 27, 2013 at 6:50pm UTC
Ok that makes sense. Thank you for that. So I changed it to this:
for(int i = 0; i < count; i++)
{
PayrollOut << Fname << Lname << ID <<
Pay << Benefit;
}
and now my output file is still all garbage.
0047F4B80047F1900047EE680047EDFC0047ED900047F4B80047F1900047
Last edited on Mar 27, 2013 at 6:51pm UTC
Mar 27, 2013 at 6:56pm UTC
You forgot to use indexes for arrays' elements.
PayrollOut << Fname[i] << Lname[i] << ID[i] <<
Pay[i] << Benefit[i];
Last edited on Mar 27, 2013 at 6:56pm UTC
Mar 27, 2013 at 6:59pm UTC
Got it! thank you very much for your help.