[英]no match for 'operator>>' in std::cin >>
我似乎遇到了嘗試從用戶輸入字符串的問題。 我之前成功完成了這項工作。 但現在它在這里拋出了錯誤。
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線)。 如果需要,我會添加它,但它似乎沒有直接與此問題相關。
沒有operator>>
用於讀取std::string
數組,你要么必須定義自己的或使用循環。
for (auto& s : Pat1)
std::cin >> s;
然后你可能不打算首先定義一個字符串數組,將字符串重新定義為string Pat1, Pat2;
其他錯誤包括不在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.