Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

getch and getchar

wcwrogerwcwroger Member Posts: 41
When i triend replacing the getch() with getchar(), it posts an error to my compiler. How do I solve it?

Roger

Comments

  • jeffpostjeffpost Member Posts: 316
    : When i triend replacing the getch() with getchar(), it posts an error to my compiler. How do I solve it?
    :
    : Roger
    :
    :
    What error, what compiler, what OS?

  • wcwrogerwcwroger Member Posts: 41
    Sorry bout the getch and getchar. I've fixed that already. Anyway, there's this problem which arises. Take a look at the code below
    [code]
    #include
    using namespace std;

    class coord {
    int x, y;
    public:
    coord() {x = 0; y = 0;}
    coord(int i, int j) {x = i; y = j;}
    friend ostream &operator<<(ostream &stream, coord ob);
    friend istream &operator>>(istream &stream, coord &ob);
    };

    ostream &operator<<(ostream &stream, coord ob)
    {
    stream << ob.x << ", " << ob.y << '
    ';
    return stream;
    }

    istream &operator>>(istream &stream, coord &ob)
    {
    cout << "Enter cordinates: ";
    stream >> ob.x >> ob.y;
    return stream;
    }

    int main()
    {
    coord a(1, 1), b(10, 23);
    cout << a ;
    cin >> a;
    cout << a;
    return 0;
    }
    [/code]

    I'm using Visual C++ in WindowMe....and when I compile..I got 7 error messages...which are..

    'x' : cannot access private member declared in class 'coord' X2
    'y' : cannot access private member declared in class 'coord' X2
    'operator <<' is ambiguous X3

    What's wrong with the program?

    Roger


  • tmlutmlu Member Posts: 15
    : Sorry bout the getch and getchar. I've fixed that already. Anyway, there's this problem which arises. Take a look at the code below
    : [code]
    : #include
    : using namespace std;
    :
    : class coord {
    : int x, y;
    : public:
    : coord() {x = 0; y = 0;}
    : coord(int i, int j) {x = i; y = j;}
    : friend ostream &operator<<(ostream &stream, coord ob);
    : friend istream &operator>>(istream &stream, coord &ob);
    : };
    :
    : ostream &operator<<(ostream &stream, coord ob)
    : {
    : stream << ob.x << ", " << ob.y << '
    ';
    : return stream;
    : }
    :
    : istream &operator>>(istream &stream, coord &ob)
    : {
    : cout << "Enter cordinates: ";
    : stream >> ob.x >> ob.y;
    : return stream;
    : }
    :
    : int main()
    : {
    : coord a(1, 1), b(10, 23);
    : cout << a ;
    : cin >> a;
    : cout << a;
    : return 0;
    : }
    : [/code]
    :
    : I'm using Visual C++ in WindowMe....and when I compile..I got 7 error messages...which are..
    :
    : 'x' : cannot access private member declared in class 'coord' X2
    : 'y' : cannot access private member declared in class 'coord' X2
    : 'operator <<' is ambiguous X3
    :
    : What's wrong with the program?
    :
    : Roger
    :
    :
    :
    Hi, I compiled the the code and there's nothing wrong with it.(also vC++)
    -Lu.
Sign In or Register to comment.