简体   繁体   English

在std :: cin >>中不匹配'operator >>'

[英]no match for 'operator>>' in std::cin >>

I seem to be having a issue with trying to get input from a user into a string. 我似乎遇到了尝试从用户输入字符串的问题。 I have done this successfully before. 我之前成功完成了这项工作。 but now it is throwing up the error here. 但现在它在这里抛出了错误。

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

In reference to this code here. 这里参考这段代码。

#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;
            };
        }
    }
}

I am wondering what is causing the issue as I have looked at other instances of this error and they seem to occur when new variable types are made without the code that lets them be "overloaded" I think it is. 我想知道是什么导致了这个问题,因为我已经查看了这个错误的其他实例,并且它们似乎发生在新的变量类型没有让它们“重载”的代码时我认为是。

But seeing as this is a string and that I have used "cin>>" before to get user input to a string I am out of ideas as what to do. 但是看到这是一个字符串,并且我之前使用“cin >>”来获取用户输入字符串,我不知道该怎么做。

As a side note there is a lot more build error information (~200 lines). 作为一个方面说明有很多更多生成错误信息(〜200线)。 If it is needed I will add it but it doesn't seem related to this issue directly. 如果需要,我会添加它,但它似乎没有直接与此问题相关。

There is no operator>> for reading into arrays of std::string , you will either have to define your own or use a loop. 没有operator>>用于读取std::string数组,你要么必须定义自己的或使用循环。

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

Then again you may have not intended to define an array of strings in the first place, redefine your strings as string Pat1, Pat2; 然后你可能不打算首先定义一个字符串数组,将字符串重新定义为string Pat1, Pat2;

Other errors include not returning a string in PatConvert , an extra bracket in if (myString[i] == filler[i2])) and this } else if (myString[i] != filler[i2]andi2 == 5) { should probably be } else if ((myString[i] != filler[i2]) && (i2 == 5)) { 其他错误包括不在PatConvert返回一个字符串, if (myString[i] == filler[i2]))一个额外括号if (myString[i] == filler[i2]))和this } else if (myString[i] != filler[i2]andi2 == 5) {应该是} else if ((myString[i] != filler[i2]) && (i2 == 5)) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM