没有运算符'>>'匹配这些操作数
no operator '>>' matches these operands
我的程序不会编译,因为它找不到与操作数匹配的内容。它访问结构Student中的映射,我不确定这是否是访问映射的确切方式。
我的程序无法编译,因为它找不到与操作数匹配的内容。它访问结构Student中的映射,我不确定这是否是访问映射的确切方式。
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <string>
#include <map>
#include <list>
using namespace std;
struct Student {
string id;
map<string, int> scores;
};
istream& operator >>(istream &is, Sudent& g) {
auto it = g.scores.begin();
is >> g.id >> it->first >> it.second;
return is;
}
在>> it->first
上,我得到这个错误:
Error: no operator ">>" matches these operands
operand types are: std::basic_istream<char, std::char_traits<char>> >> const std::string
您可以使用临时变量
std::string tempStr;
int tempInt;
is >> g.id >> tempStr >> tempInt;
scores.insert( std::pair<std::string,int>(tempStr , tempInt));
错误是由于it->first
的类型是const string
,而不是string
。
除此之外,您还需要找到一种方法,通过读取(未知)数量的字符串和相应的int来读取映射。如何做到这一点取决于它们在文件中的存储方式。
相关文章:
- 控制允许动态运行c++的并发操作数
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- EASTL矢量<向量<int>>连续的
- 错误 C2679:二进制"<<":未找到采用类型 'std::string_view' 的右侧操作数的运算符(或者没有可接受的转换)
- C++ 带有向量的 IF 计算操作数
- 是否所有C++运算符都接受操作数?
- 一元*运算符的操作数是否期望一个 prvalue
- 与'operator='不匹配(操作数类型'String'且"void")
- 不正确的操作数类型 MSVC
- C2678 二进制 '==':未找到采用 'Card' 类型左操作数的运算符(或者没有可接受的转换)
- 错误:类型"double()"和"double()"的操作数无效到二进制&quo
- 我的运算符重载是否有效<<(流插入)左操作数不是 ostream
- 没有运算符"="与这些操作数匹配,JUCE 窗口演示应用程序
- 如果我在指针中使用 ++ 操作数,我的值就会出错
- 二进制表达式的操作数无效 - 使用 for 和迭代器
- C2679 二进制"<<":未找到采用右操作数类型的运算符
- CPP 运算符重载操作数位置 [] 与 ==
- int* 和 int[] 类型对二进制运算符 + 的操作数无效
- 错误:二进制'operator*' 'float'和'float[0]'类型的操作数无效
- 运算符'<'不能应用于类型 'string' 和 'string' 的操作数