C++ Primer
Sample Code

by
HPO SOFT
November 2003

//
// This program illustrates reading and printing a sequential file.
//

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{

ifstream InClientFile;
int Account;
string Name;
float Balance;

// Open and test input file.

InClientFile.open( "clients.txt", ios::in );

if( !InClientFile )
{

cerr << "Client file could not be opened." << endl;

}
else
{

// setup column headers
cout << "Account" << "\t" << "Name" << "\t" << "Balance" << endl;

while( InClientFile >> Account >> Name >> Balance )
{

cout << Account << "\t" << Name << "\t" << Balance << endl;

}

// we're done close file.

cout << endl;
InClientFile.close();

}
return 0;

}

 

RETURN