Im writing a banking system program for one of my assignments using classes, i've got the some basic stuff done but I can't for the life of me work out how to read data out of a file i've previously created and display it on screen. (I've cut the code down so it's easier to read on here)

The part im stuck on is the Current::DisplayDetails class, doing it the way I have at the moment throws an error:

error C2664: 'class std::basic_istream<char,struct std::char_traits<char> > &__thiscall std::basic_istream<char,struct std::char_traits<char> >::getline(char *,int)' : cannot conv
ert parameter 1 from 'class std::basic_fstream<char,struct std::char_traits<char> >' to 'char *'

Can anyone help? :)

#ifndef H_account
#define H_account

class Account
	void createNewAccount();
	void displayDetails(void);
	void saveAccount();
	int iAccNum;
	char sCusName[30];
	char sCusAddress[30];
	double dAccBalance;
	char name[30];

class Current : public Account
	void setDetails(void);
	void displayDetails(void);
	void saveAccount();
	double dOverdraftLimit;


#include <string>
#include <fstream>
#include <iostream>
#include "account.h"

using namespace std;

void Account::createNewAccount(void)
	cout << "\nPlease enter a new account number:>";
	cin >> iAccNum;

	cout << "\nPlease enter the customers name:>";

	cout << "\nPlease enter the customers address:>";
	cin >> sCusAddress;

	cout << "\nPlease enter the starting account balance:>" << (char)156;
	cin >> dAccBalance;

void Current::saveAccount()
	ofstream AccFile("current.dat", ios::out | ios::binary | ios::app);
	AccFile << iAccNum << endl;
	AccFile << sCusName << endl;
	AccFile << sCusAddress << endl;
	AccFile << dAccBalance << endl;
	AccFile << dOverdraftLimit << endl;

void Current::setDetails()
	cout << "\nPlease enter the over overdraft limit:>";
	cin >> dOverdraftLimit;

void Current::displayDetails(void)
	fstream checkFile("current.dat", ios::in | ios::binary | ios::beg);
	cin.getline(checkFile, sCusName);

	if(name == sCusName)
		cout << "Account Overview \n" << endl;
		cout << "Account Name: " << sCusName << "\n";
		cout << "Account Number: " << iAccNum;

		cout << endl;
		checkFile >> dAccBalance;
		cout << "Balance:" << (char)156 << dAccBalance << endl;

Edited 5 Years Ago by samoz83: n/a

fstream checkFile("current.dat", ios::in | ios::binary | ios::beg);
cin.getline(checkFile, sCusName);

getline is looking for a char pointer instead of basic_fstream

You don't need the cin because you are not taking input from the keyboard. Use checkFile.getline(sCusName,30); If you have multiple customers in a file you're going to need a loop to access the one you need.

This article has been dead for over six months. Start a new discussion instead.