i get error c2886( when i use using std::cout; using std::string;) i change to using

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • donthomasino
    New Member
    • Apr 2010
    • 3

    #1

    i get error c2886( when i use using std::cout; using std::string;) i change to using

    i get error c2886( when i use using std::cout; using std::string;) and when i change to (using namespace std;
    using namespace std;) i got error c2059

    #include <iostream>
    #include <string>
    #include "Vector.h"
    #include "Car.h"
    //using namespace std::cout;
    //using namespace std::string;
    using namespace std;
    using namespace std;

    class Inventory {
    public:
    Inventory()
    {
    }

    bool isExist(string const& vin)
    {
    for (int i = 0; i < data.size(); i++)
    if (data.get(i)->getVIN() == vin)
    return true;

    return false;
    }

    void addRecord(Car* record)
    {
    if (data.size() < 20)
    {
    bool found = false;
    for (int i=0; i < data.size() && !found; i++)
    if (data.get(i) == record)
    found = true;

    if (!found && record->getYear() > 1980)
    data.push_back( record);
    else if (found)
    cout << "Existing Record: " << *record << " not added!\n";
    }
    else
    cout << "Inventory Full:" << *record << "!\n";
    }

    void removeRecord(st ring const& vin)
    {
    if (data.size() > 0)
    {
    if( isExist(vin)) {
    for(int i=0; i<data.size(); i++)
    if( data.get(i)->getVIN() == vin)
    {
    data.erase(i);
    cout << "Car removed successfully!\n ";
    break;
    }
    } else
    cout << "Car not found.\n";
    }
    else
    cout << "No record in the inventory!\n";
    }

    void showRecords()
    {
    if (data.size()>0 )
    {
    for(int i=0; i<data.size(); i++)
    {
    cout << *data.get(i) << "\n";
    }
    }
    else
    cout << "No record in the inventory!\n";
    }

    void showRecords(int year, string const& model)
    {
    if (data.size()>0 )
    {
    for(int i=0; i<data.size(); i++)
    {
    if (data.get(i)->getYear() == year && data.get(i)->getModel() == model)
    cout << *data.get(i) << "\n";
    }
    }
    else
    cout << "No record in the inventory!";
    }

    private:
    Vector<Car> data;
    };
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Have you defined how cout is supposed to handle a Car object?
    Perhaps you want a function in Car like
    string GetInfo();

    Then you could write:
    cout << record.GetInfo( );

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      It would be better to write a series of member functions that return const pointers or referecnes toi the member data. That way you can format the display many different ways instead of one.

      If there is only one display format, I would write an operator<< rather than an accessor function.

      Comment

      Working...