Errors with infiling and outfiling

The program is an ATM machine that you pretty much just make deposits, withdraw, and check your balance. It is a school project.

Here is the complete code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iomanip>
#include <iostream>
#include <conio.h>
#include <math.h>
#include <fstream>
using namespace std;
//In the main have the create and log in.
//Ask the user if they want to create an account, if yes then have them create an account then restart the program.
//Have the user log in, if the pin is invalid close the program. Have switch statement for the other options of...
//Each of the following are void ___ ()
//Check your balance: Displays your current balance.
//Make a withdraw: Enter in the amount to be taken out, subtract that from the total, use an if to see if the person has sufficient funds with subtraction
//Make a deposit: Enter in the amount to enter, add it to the total, display new amount.
//This program is pretty broken right now expect a ton of errors to fix later.
void deposit ()
{
    ifstream infile;
	string apin;
	int pin,found,searchpin,choice2;
	char choice;
	double wealth, deposit;

    cout<<"Enter in your account 4-digit pin: "; //Must have to enter in a file to open.
    getline (cin,apin);
    infile.open(apin+".txt");
    infile.open(apin.c_str());
	cout<<endl<<"How much money do you wish to deposit?";
	cin>>deposit;
	wealth = deposit + wealth;
	cout<<endl<<"Your account now has: $"<<wealth;

}

void withdraw ()
{
    ifstream infile;
	string apin;
	int pin,found,searchpin,choice2;
	char choice;
	double wealth, withdraw;

	cout<<"Enter in your account 4-digit pin: "; //Must have to enter in a file to open.
    getline (cin,apin);
    infile.open(apin+".txt");
    infile.open(apin.c_str());
	cout<<endl<<"How much money do you wish to withdraw?";
	cin>>withdraw;
	wealth = wealth - withdraw;
	cout<<endl<<"Your account now has: $"<<wealth;
}

void checkbalance ()
{
    ifstream infile;
	string apin;
	int pin,found,searchpin,choice2;
	char choice;
	double wealth;

	cout<<"Enter in your account 4-digit pin: "; //Must have to enter in a file to open.
    getline (cin,apin);
    infile.open(apin+".txt");
    infile.open(apin.c_str());
	cout<<endl<<"Your account currently has: $"<<wealth;
}

int main ()
{
	ifstream infile;
	string apin;
	int pin,found,searchpin,choice2;
	char choice;
	double wealth;

	cout<<"Do you have an account with us? (Y) or (N).";
	cin>>choice;

	if (choice == 'N')
        {
            cout<<"Please enter in the following information for creating the account: "<<endl;
            cout<<"Enter in your account 4-digit pin: "; //Must have to enter in a file to open.
            getline (cin,apin);
            apin=apin+".txt";
            infile.open(apin.c_str());
            cout<<endl<<"Enter in your 4-digit pin number: ";
            infile>>pin;
            cout<<"Please enter in how much money you are going to be depositing from the start: ";
            cin>>wealth;
            cout<<endl<<"Your account has been created. Please log off and back on.";
        }

	else if (choice == 'Y') //This is for logging in, use a nested if for if the password is right and all...then use the nested if so you can access the other options of dipositing, withdrawing, etc.
	{
        found = 0;
        cout<<"Enter in your account PIN: ";
        getline (cin,apin);
        infile.open(apin+".txt");
        cout<<"Enter in your PIN number: ";
        cin>>searchpin;
        infile>>pin;

        if (searchpin == pin)
            {
                cout<<"Welcome! Please choose which option you wish to prusuit"<<endl;
                cout<<"Make a deposit (1)"<<endl;
                cout<<"Withdraw money (2)"<<endl;
                cout<<"Check your balance (3)"<<endl;
                cin>>choice2;

                    switch (choice2)
                    {
                        case 1: deposit();
                        break;
                        case 2: withdraw();
                        break;
                        case 3: checkbalance();
                        break;
                    }
            }

    }
return 0;
}


Here is where the error is exactly, at least one of them
 
        infile.open(apin+".txt");


The error is the same for lines 25, 44, 62, and the above 97.

Here is the error

E:\40212.cpp||In function 'void deposit()':|
E:\40212.cpp|25|error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\fstream|525|note: candidates are: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]|
E:\40212.cpp||In function 'void withdraw()':|
E:\40212.cpp|44|error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\fstream|525|note: candidates are: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]|
E:\40212.cpp||In function 'void checkbalance()':|
E:\40212.cpp|62|error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\fstream|525|note: candidates are: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]|
E:\40212.cpp||In function 'int main()':|
E:\40212.cpp|97|error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\fstream|525|note: candidates are: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]|
||=== Build finished: 4 errors, 0 warnings ===|


Code::Blocks keeps opening up fstream as well with this. My teacher gave me the code to make the file name...but now it is not working. I am sure there are other small errors, but I can't even see them with these errors in the way.
infile.open(apin+".txt");


This function, open, accepts a char pointer. You're feeding it a string. A char pointer is not the same as a string.
do
apin+=".txt";
and then do
infile.opne(apin.c_str()); if you want to open the file with a string.
also i do not think you are not using any functions from math.h or conio.h or iomanip.h including this will just make your program take longer to compile.
and if you want to use string include string.h
Last edited on
and if you want to use string include string.h


The C++ string class lives in <string>. <string.h> is a C header that contains functions to help play with char-pointers. It does NOT contain the C++ string class.
string and string.h were melded with my compiler. so for me they are interchangeable. but you should still include the library if you want to use strings.
Well then you're using some kind of horrific mutant compiler that isn't conformant with the C++ language. You can get modern C++ compilers for free.
i use xcode quite happily. works better than a lot of others such as netbeans and dev C++ and i like it a bit more than eclipse although eclipse is really really nice.
xcode is not a compiler. It's an IDE.
that has a compiler with it... it has the Apple LLVM compiler... and it works better than almost every other compiler i have used.
Topic archived. No new replies allowed.