与 std::cin >>中的"运算符>>"不匹配
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行)。如果需要,我会添加它,但它似乎与这个问题没有直接关系。
没有用于读取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)) {
相关文章:
- 为什么比较运算符如此快速
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 使用C++中的模板和运算符重载执行矩阵运算
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 增量运算符与后缀混淆
- 一个关于在C++中重载布尔运算符的问题
- 运算符C++ "delete []"仅删除 2 个前值
- 模板类无法识别友元运算符
- 我可以使用条件运算符初始化C风格的字符串文字吗
- 关闭||运算符优化
- 通过继承类使用来自不同命名空间的运算符
- C++Cast运算符过载
- 如何使用AngelScript注册SFML Vector2运算符
- 重载元组索引运算符-C++
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 为什么Mat类的两个对象可以在不重载运算符+的情况下添加
- 多个If语句与使用逻辑运算符计算条件的单个语句的比较
- 布尔比较运算符是如何在C++中工作的
- 重载运算符new[]的行为取决于析构函数
- 是否需要使用 - &gt;运算符在C 中调用成员函数时