string and class error
i have created a class which contains all the information needed for a
program based on accounts, this is shown below. When compiled the
string "word" (in function writetofile) which is initialised in the
constructor is apparently "undeclared", yet it has been declared in
the constructor.
i am new to c++ class programming, do i need to also declare it, as
well as initialise? and if not, what is the problem and how can it be
solved?
thanks
wilson
#include <iostream>
#include <fstream>
#include <time.h>
#include <cstdlib>
#include <cstring>
using namespace std;
class Account
{
friend void new_account();
public:
Account(){string word = "hello";}//can eventually be user
inputted
void returnbalance() { std::cout << balance <<
std::endl; }
void writetofile()
{
string extension = ".txt";
ofstream writetofile;
writetofile.open((word + extension).c_str());
writetofile << balance;
}
void deposit(float amount)
{
balance = balance + amount;
std::cout << "$" << amount << " Has been deposited
into your account";
std::cout << std::endl << "Your balance is now $" <<
balance;
}
virtual void withdraw(float amount)
{
if(amount < balance)
{
balance = balance - amount;
std::cout << "$" << amount << "has been
withdrawn from your account";
std::cout << std::endl << "Your balance is
now $" << balance;
}
else
{
std::cout << std::endl << "Insufficient funds,
your balance is $" << balance;
}
}
float balance;
private:
int pin_number;
int account_number;
};