c++ - 辛>> "no operator matches these operands"

标签 c++ cin

我一直在 visual studio 2012 控制台模式下处理一个 C++ 项目,我一直在使用 cin 函数时遇到这个奇怪的持续性错误。

>>> 下,我得到一条红线,程序告诉我没有运算符匹配这些操作数。 我已经在单独的方法中初始化了所有数组元素。

这是一个片段示例(实际代码包含更多变量):

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 是一个数组,数据类型为“taxiDetails”,结构如下:

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

最佳答案

问题是说string没有 operator>>方法,但它确实...

  1. 你忘记了吗#include <string>在该文件的顶部?
  2. 也许尝试使用 getline(std::cin, allTaxiDetails[I].taxiRank, '\n'); .
  3. 定义operator>>为您的结构。

关于c++ - 辛>> "no operator matches these operands",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21030214/

相关文章:

c++ - 检查 cin 输入流产生一个整数

c++ - 在 C++ 中读取文件时跳过 EOF

c++ - * x++和* y + = 1之间的差异

c++ - 让 linux SDL2 程序在没有安装 SDL2 的计算机上运行?

c++ - Cin.Ignore() 不工作

c++ - 如何限制 C++ 中用户输入的最大字符数?

c++ - 不能在一行中输入 (cin) 超过 10 个整数并用空格分隔到数组中吗?

C++ EVP_EncriptUpdate 重写堆栈?

c++ - OpenCV C++ 从矩形区域设置 ROI

c++ - 收到输入并测试它是否是 C++ 中的 int 后的无限循环