aborting error

when i run this program it asks me for the first file , then when it asks me for the second file i get an abort error, I am not sure what I am doing wrong, I am supposed to print out information from a datafile i created to a different file formatted, im using linux if that matters

// A program to read data file
// and print a formatted report

#include<iostream>
#include<fstream>
#include<cstring>
#include<iomanip>
using namespace std;

//function prototypes
void Initialize(fstream&bankfile,fstream&printerfile);
void Readandprint(fstream&bankfile,fstream&printerfile);
void Finalize(fstream&bankfile,fstream&printerfile);

main()
{
fstream bankfile;
fstream printerfile;
Initialize(bankfile,printerfile);
Readandprint(bankfile,printerfile);
Finalize(bankfile,printerfile);
}//main

void Initialize(fstream&bankfile,fstream&printerfile)
{
char Filename[51];
char printfile[51];
cout << "Enter name of the file to be open:";
cin >> Filename;
bankfile.open(Filename, ios::in);
cout << "Enter name of the file to be sent to:";
cin >> printfile;
printerfile.open(printfile,ios::out);
if(bankfile.fail())
{
cout << "Error on opening the file"
<< endl;
}//if
if(printerfile.fail())
{
cout<< " Error on opening the file"
<<endl;
}//if
}//Initialize

void Readandprint(fstream&bfile,fstream&pfile)
{
int acctid;
char fname[11];
char lname[11];
double balance;

bfile >> fname;

while(!bfile.eof())
{
bfile >> lname;
pfile<< setw(15)<<acctid
<<setw(5)<<fname << lname
<<setw(5) << balance
<<endl;
bfile >> fname >> lname;
}//while
}//Inputandwrite

void Finalize(fstream&bfile,fstream&pfile)
{
bfile.close();
cout<< " Full closed- terminating"
<<endl;
pfile.close();
cout<< " Closing everything"
<<endl;
}//finalize


I think it is this: when you use cin>> to read in data for the first file name, when you hit enter you put '\n' into the buffer that is not used. When you try to read the next filename, you read in that '\n' as the end of a line, resulting in your second file name being nothing/garbage.
im sort of confused with what your saying, im confused overall with this thing
Topic archived. No new replies allowed.