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.
As a side note there is a lot more build error information (~200 lines). 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.
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;
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)) {
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.