c++中的STL映射错误C2679
STL Map error C2679 in C++
当我尝试打印成对的int &STL Map中的字符串:
这是我使用的代码:
#include <iostream>
#include <utility>
#include <map>
using namespace std;
typedef map<int,string> intID;
int main(){
intID ID;
ID.insert(pair<int,string>(123,"studentname1"));
ID.insert(pair<int,string>(124,"studentname2"));
ID.insert(pair<int,string>(122,"studentname3"));
intID::iterator IDIter;
for(IDIter = ID.begin();IDIter != ID.end();++IDIter){
cout <<"ID: " << IDIter->first <<", Name: " << IDIter->second << endl;
}
}
错误发生在", Name: " << IDIter->second
部分,<<
下划线表示"没有操作符匹配这些操作数"
编译错误是:
错误1错误C2679:二进制'<<':没有找到带a的操作符'std::string'类型的右操作数(否则不接受)转换)
我试图打印出这对中的第二个成员(studentname)我是STL映射的新手,所以我不确定我做错了什么,我需要改变什么?
您需要包含<string>
标头。您只能通过偶然包含其他头文件来使用std::string
类型。你不能依赖这个。包括<string>
也会带来operator<<
的重载,允许您输出字符串。
相关文章:
- 错误 C2679:二进制"<<":未找到采用类型 'std::string_view' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误 C2679 二进制"<<":未找到采用类型为 'T' 的右侧操作数的运算符
- 如何修复用于根据参数返回不同类型的模板类中的错误C2679?
- 错误 C2679:二进制'<<':找不到采用类型 'overloaded-function' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误 C2679:二进制"<<":未找到采用类型 'mystring' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误 C2679:二进制'>':找不到采用类型 'int' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误 C2679 二进制"=":未找到采用类型 'int' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误 C2679 二进制"=":未找到采用类型 'int' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误 C2679:二进制"[":找不到采用右侧操作数的运算符
- C++ 编译器错误 C2679:二进制"=":找不到运算符
- 在模板中使用"+"运算符添加模板类和参数类时出现错误 C2679
- 错误C2679-C++-找不到运算符
- 错误 C2679。错误 1 错误 C2679:二进制'<<':找不到采用类型 'std::vector<_Ty>' 的右侧操作数的运算符
- 错误 C2679:二进制'=':找不到采用类型 'Set<ElemType>' 的右侧操作数的运算符
- 错误 C2679:二进制"[":未找到采用类型为"const VerseKey"的右操作数的运算符(或者没有可接受的转换)
- 错误 C2679:二进制"=":未定义采用类型右侧操作数的运算符
- 错误 C2679:二进制"+":找不到采用类型右侧操作数的运算符
- 使用LARGE_INTEGER会给我返回错误错误 C2679:'='二进制找不到需要右侧操作数的运算符
- 错误 C2679 模板类
- 错误 C2679:二进制'=':找不到采用类型为"std::basic_string的右侧操作数的运算符