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;
};
Issue is saying that string
doesn't have the operator>>
method, but it does...
#include <string>
at the top of that file?getline(std::cin, allTaxiDetails[I].taxiRank, '\n');
.operator>>
for your struct.It seems you are trying to read an object of type std::string
for which you somehow obtained the class definition (e.g. by including <iostream>
) but you didn't get all the necessary operations! Make sure you are including <string>
:
#include <string>
// ...
It is quite common that some headers provide definitions of some other classes but actually don't use the entire header to get the definitions. Since std::string
is in some places needed to declare IOStreams it is fairly likely that it will be defined but probably not by including its full header.
I believe forget #include < string > this critical header is the error source. It happened to me as a beginner of C++.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With