96 errors! probably because of std.

Hi
It's the first class I'm writing & now I got 96 errors!

I think there should be something wrong with std.

I know there might be some common problems like semi colon or some logical errors, but I think most of the errors have the same source.

Here it is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//Account.h
#include <iostream>
using namespace std;

class Account
{
public:
	Account(int data);
	void credit(int data);
	void debit(int data);
	int getbalance();
private:
	int Amount;
};



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
//Account.cpp
#include <iostream>
#include "Account.h"
using namespace std;

class Account
{
public:
    Account::Account(int data)
        if(data>=0)
            credit(data);
        else
            cout<<"The entered amount must not be smaller than 0.\nAmount is set to 0."<<endl;
    void Account::credit(int data)
        if(data>0)
            Amount+=data;
        else
            cout<<"The entered amount must be greater than 0.\nOperation cancelled."<<endl;
    void Account::debit(int data)
        if(data<0)
            cout<<"The entered amount must be greater than 0.\nOperation cancelled."<<endl;    
        else if(data>Amount)
            cout<<"Debit amount exceeded account balance."<<endl;
        else
            Amount-=data;
    int Account::getbalance()
        return Amount;
private:
    int Amount=0;
};



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
//3-1.cpp (using the class Account)
#include <iostream>
#include<string>
#include "Account.h"
using namespace std;

void main()
{
    char operation='1';
    int money;
    Account first(0);
    
        cout<<"Welcome\n";
        do
        {
        cout<<"Enter 1 to credit,2 to debit, 3 to get balance, 0 to exit:\n";
        getline(cin,operation);
        switch(operation)
        {
        case '1':
            {
                cout<<"Enter the amount of money tou want to credit:";
                cin<<money;
                first.credit(amount);
                break;
            }
        case '2':
            {
                cout<<"Enter the amount of money tou want to debit:";
                cin<<money;
                first.debit(amount);
                break;
            }
        case '3':
            {
            first.getbalance();
            break;
            }
        }while(operation!='0');
    cout<<"Thanks for using e-ATM!";
}
    


Most of the errors are like this:
c:\users\hp\documents\visual studio 2008\projects\account\account\3-1.cpp(17) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &' from 'char'
d:\application\microsoft visual studio 9.0\vc\include\string(527) : see declaration of 'std::getline'
Last edited on
'getline' expects a std::string as the second paramter not a char.

remove using namespace std; from the header. It's not used there. Better remove it at all.
closed account (zb0S216C)
std::getline( ) doesn't accept a char type-specifier as its output buffer, only std::string is accepted. However, a char type is accepted as the delimiting character.

References:
std::getline( ):http://www.cplusplus.com/reference/string/getline/


Wazzak
closed account (1vRz3TCk)
Your Account.cpp also needs looking at:

like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "Account.h"


Account::Account(int data)
{
    // your code here
}

void Account::credit(int data)
{
    // your code here
}

void Account::debit(int data)
{
    // your code here
}

int Account::getbalance()
{
    // your code here
}
Thanx everyone.Changing getline to cin removed 2 errors. 94 to go!

codemonkey:You mean brackets? But every function has only one "if".
edit:yes,you were right.

Almost all of the errors are "error C2784".
Last edited on
eeeh,I found my silly mistake

90 errors were because lines 23 & 30 of 3-1.cpp

read n' laugh :D
Last edited on
void main()?
Thanks.I'll change that to int main().I heard void main() is not suitable for important programs & sometimes may cause crash.So I should practice it from now.

(It still has some small errors.But the main problem is solved)
I heard void main() is not suitable for important programs & sometimes may cause crash.


Also, it's just plain wrong and if your compiler didn't even warn you, delete your compiler and get a better one. There are good, free compilers available.
Isn't Microsoft Visual C++ trusted?
closed account (zb0S216C)
Yes, Microsoft is trustworthy; they just like to be different, as always.

Wazzak
closed account (1vRz3TCk)
Yes it is, the case is being overstated. I believe that all compilers work in a non-standard mode (extensions) and have to be told to only use standard c++ via switches.
I realize this is after the fact, and I'm not trying to be particularly mean, but I always have to laugh when I see stuff like this.

96 errors! probably because of std.
It's the first class I'm writing & now I got 96 errors!

I think there should be something wrong with std.

Yes, I'm sure that something that has been tested and used by hundreds of thousands of competent programmers is causing your 96 errors. Just like blaming the tennis racket when you miss the ball. Or the keyboard when you frob the wrong keys.

Perhaps you ought to learn and practice more before blaming the tools for your mistakes?

Almost all of the errors are "error C2784".

Microsoft says that's because you screwed up your template arguments. For example:
c:\users\hp\documents\visual studio 2008\projects\account\account\3-1.cpp(17) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &' from 'char'
This means that you confused the compiler when you tried to treat a char as a std::string.

Moschops wrote:
Also, it's just plain wrong and if your compiler didn't even warn you, delete your compiler and get a better one. There are good, free compilers available.
Ehsan Imani wrote:
Isn't Microsoft Visual C++ trusted?
Framework wrote:
Yes, Microsoft is trustworthy; they just like to be different, as always.
CodeMonkey wrote:
Yes it is, the case is being overstated. I believe that all compilers work in a non-standard mode (extensions) and have to be told to only use standard c++ via switches.

Microsoft makes one of the finest C++ compilers available, that even Stroustrup likes. Oh, and they also have a free version. But wait! The OP is already using a better version than the free one!

As CodeMonkey said, all compilers have their preferred modes of operation. Every one needs to be told to check the code as strictly as possible (or required): turn on all warnings and errors when compiling.
Topic archived. No new replies allowed.