Read code
#include <iostream>
using std::cerr;
using std::cout;
using std::endl;
using std::fixed;
using std::ios;
using std::left;
using std::right;
using std::showpoint;
#include <fstream>
using std::ifstream;
#include<iomanip>
using std::setw;
using std::setprecision;
#include <string>
using std::string;
#include <cstdlib>
//using std::exit;
void outputLine( int, const string, double );
//void outputLine( int,const string, double );
int main()
{
ifstream inClientFile( "clients.txt", ios::in );
if ( !inClientFile )
{
cerr<< "File could not be opened"<<endl;
// exit( 1 );
}
int account;
//char name[30];
char name[30];
double balance;
cout<< left << setw( 10 ) << "Account" << setw( 13 )
<< "Name" << "Balance" << endl << fixed << showpoint;
while ( inClientFile >> account >> name >> balance )
outputLine( account, name, balance );
return 0;
}
void outputLine( int account, const string name, double balance )
{
cout << left << setw(10) << account << setw(13) << name
<< setw(7) << setprecision(2) << right << balance << endl;
}
and here's the Write code
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
using std::ios;
using std::cerr;
#include<fstream>
using std::ofstream;
#include<cstdlib>
//using std::exit;
int main()
{
ofstream outClientFile("clients.txt", ios::out);
if (!outClientFile)
{
cerr<<"File name could not be opened"<<endl;
exit(1);
}
cout<<"Enter the account,name,balance."<<endl
<<"Enter end-of-file to end input.\n?";
int account;
char name[30];
double balance;
while (cin>>account>>name>>balance)
{
outClientFile<<account<< ' ' <<name<< ' ' <<balance<<endl;
cout<<"?";
}
return 0;
}
any kind of help would be greatly appreciated. Thanks!

New Topic/Question
Reply




MultiQuote




|