Hey everyone, another question on my banker program, here it is. Im trying to have a variable in my class that creates a file when the class is initiallized. But, when i open the file using a varialbe string instead of a static string..it doesnt work. Heres what im talking about.
When i put this in, it compiles without any error..look in the bold
Code:#include <iostream> #include <fstream> #include <string> using namespace std; class Banker { public: const static int CHECKING = 1; const static int SAVINGS = 0; Banker(string name, int iDeposit); ~Banker(); int GetBalance(int account); int Deposit(int amount, int account); int Transfer(int amount, Banker reciever); protected: int cBalance; int sBalance; string bName; ofstream oAccount; ifstream rAccount; }; Banker::Banker(string name, int iDeposit) { cBalance = iDeposit; bName = name; oAccount.open("Blah.txt", ios::app); } int main() { cout<< "Welcome to the Cullen Familly Banking Program.\n"; cout<< "Please select a choice:\n\n"; cout<< "1. Deposit\n"; cout<< "2. Check Balance\n"; cout<< "3. Make a transfer\n\n"; cin.get(); return 0; }
Now, but when i make this simple adjustment i get errors...again look in the bold
Here are the errors that i get when trying to compile this...:Code:#include <iostream> #include <fstream> #include <string> using namespace std; class Banker { public: const static int CHECKING = 1; const static int SAVINGS = 0; Banker(string name, int iDeposit); ~Banker(); int GetBalance(int account); int Deposit(int amount, int account); int Transfer(int amount, Banker reciever); protected: int cBalance; int sBalance; string bName; ofstream oAccount; ifstream rAccount; }; Banker::Banker(string name, int iDeposit) { cBalance = iDeposit; bName = name; oAccount.open(bName + ".txt", ios::app); } int main() { cout<< "Welcome to the Cullen Familly Banking Program.\n"; cout<< "Please select a choice:\n\n"; cout<< "1. Deposit\n"; cout<< "2. Check Balance\n"; cout<< "3. Make a transfer\n\n"; cin.get(); return 0; }
c:\cpp stuff\banking\bankingmain.cpp: In method `Banker::Banker(basic_string<char,string_char_trai ts<char>,__default_alloc_template<false,0> >, int)':
c:\cpp stuff\banking\bankingmain.cpp:36: no matching function for call to `ofstream:pen (basic_string<char,string_char_traits<char>,__defa ult_alloc_template<false,0> >, ios:
pen_mode)'
C:\DEV-C_~1\Include\G__~1\fstream.h:78: candidates are: void ofstream:pen(const char *, int = ios:
ut, int = 436)
Any help much appreciated..thanks, justin



LinkBack URL
About LinkBacks
pen (basic_string<char,string_char_traits<char>,__defa ult_alloc_template<false,0> >, ios:


