cin >> "no operator matches these operands"

user3163612 picture user3163612 · Jan 9, 2014 · Viewed 49.9k times · Source

I've been working on a C++ project in visual studio 2012 console mode and I keep getting this strange persistent error with the cin function.

Under the >> I get a red line and the program tells me no operator matches these operands. I have initialized all the array elements in a separate method.

Here's a snippet example (The actual code contains many more variables):

for (int i = 0; i < 14; i++)
{
    cout << "For taxi: " << i+1 << "Please input the taxi rank they are currently parked at, if at all ('Train Station', 'South Walls' or 'Chell Road')" << endl;
    cin >> allTaxiDetails[i].taxiRank;
}

allTaxiDetails is an array, of data type "taxiDetails" which is this structure:

struct taxiDetails { 
    string taxiDriverSurname; 
    int taxiID; 
    int taxiCoordinates; 
    int numberOfSeats; 
    bool taxiContainsCustomerYesNo; 
    bool WheelChairAccessibleVehicle; 
    string taxiRank; 
    fareDetails fareDetailsForTaxi; 
    bool taxiAvaliable; 
};

Answer

Keeler picture Keeler · Jan 9, 2014

Issue is saying that string doesn't have the operator>> method, but it does...

  1. Did you forget #include <string> at the top of that file?
  2. Maybe try using getline(std::cin, allTaxiDetails[I].taxiRank, '\n');.
  3. Define operator>> for your struct.