Thread: istream >> overloading

  1. #1
    Registered User
    Join Date
    Aug 2001

    Unhappy istream >> overloading

    I am using visual c++ and I am having trouble overloading the >> operator. When I compile it says that _simNo is private and it can't be accesed. Why doesn't this work:


    #include <string>
    #include <iostream>

    using namespace std;

    class SimCard
    SimCard(const string& tempSimNo = "", const string& tempCustName = "", const string& tempAddress = "", const string& tempSuburb = "", const float& tempCredit = 0.0);
    friend istream &operator>> (istream& is, SimCard& sim);
    void setCredit(const float credit);
    string getSimNo() const;

    string _simNo;
    string _custName;
    string _address;
    string _suburb;
    float _credit;


    #include "SimCard.h"

    using namespace std;

    SimCard::SimCard(const string& tempSimNo, const string& tempCustName, const string& tempAddress, const string& tempSuburb, const float& tempCredit)
    _simNo = tempSimNo;
    _custName = tempCustName;
    _address = tempAddress;
    _suburb = tempSuburb;
    _credit = tempCredit;

    istream& operator>> (istream& is, SimCard& sim)
    getline(is, sim._simNo);
    getline(is, sim._custName);
    getline(is, sim._address);
    getline(is, sim._suburb);
    return is;

    void SimCard::setCredit(const float credit)
    _credit = credit;

    string SimCard::getSimNo() const
    return _simNo;



  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    I don't know.. it worked fine for me.. compiled with -pedantic flag (strictest) option in gcc.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Overloading fstream's << and >> operators
    By VirtualAce in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2007, 03:17 AM
  2. Overloading << and >>
    By Enahs in forum C++ Programming
    Replies: 2
    Last Post: 09-15-2005, 04:33 PM
  3. Compile errors with overloading >> operators
    By GMHummerH1 in forum C++ Programming
    Replies: 1
    Last Post: 12-19-2004, 07:13 PM
  4. << and >> overloading
    By Armatura in forum C++ Programming
    Replies: 2
    Last Post: 12-07-2003, 06:19 PM
  5. problems with >> istream overloading
    By rip1968 in forum C++ Programming
    Replies: 4
    Last Post: 05-06-2002, 03:38 PM