与 std::cin >>中的"运算符>>"不匹配

no match for 'operator>>' in std::cin >>

本文关键字:gt 运算符 不匹配 std cin 中的      更新时间:2023-10-16

我似乎在尝试将用户输入到字符串中时遇到了问题。我以前已经成功地做到了。但现在它在这里抛出了错误。

error: no match for 'operator>>' in 'std::cin >> Pat1'

此处参考此代码。

#include <iostream>
#include <cmath>
#include <cctype>
#include <sstream>
using namespace std;
string PatConvert(string myString);
int main(){
    string Pat1[5],Pat2[5];
    cout<<"Please give the two five charter patterns";
    cin>>Pat1;//where the error occurs.
    cin>>Pat2;
    Pat1=PatConvert(Pat1);
    Pat2=PatConvert(Pat2);
    if (Pat1==Pat2){
        cout<<"The patterns match!";
        return 0;
    }else {
        cout<<"The patterns don't match!";
    }
}
string PatConvert(string myString){
    string filler[5];
    int fillerCount=1;
    for (int i=0; i<myString.length(); i++){
        for (int i2=0; i2<filler.length(); i2++){
            if (myString[i]==filler[i2])){
                break;
            }else if(myString[i]!=filler[i2]andi2==5){
                filler[fillerCount]=myString[i];
                myString[i]=fillerCount;
                return myString;
            };
        }
    }
}

我想知道是什么导致了这个问题,因为我已经查看了这个错误的其他实例,当在没有代码的情况下创建新的变量类型时,它们似乎会发生,我认为是的

但是,由于这是一个字符串,而且我以前使用过"cin>>"来获得字符串的用户输入,我不知道该怎么办。

附带说明的是,还有很多构建错误信息(约200行)。如果需要,我会添加它,但它似乎与这个问题没有直接关系。

没有用于读取std::string数组的operator>>,您必须定义自己的或使用循环。

for (auto& s : Pat1)
  std::cin >> s;

再说一遍,你可能一开始就不打算定义一个字符串数组,把你的字符串重新定义为string Pat1, Pat2;

其他错误包括在PatConvert中没有返回字符串,在if (myString[i] == filler[i2]))中有一个额外的括号,而这个} else if (myString[i] != filler[i2]andi2 == 5) {可能是} else if ((myString[i] != filler[i2]) && (i2 == 5)) {