C++ C+中的STL映射错误C2679+;

C++ C+中的STL映射错误C2679+;,c++,stl,containers,C++,Stl,Containers,我在试图打印STL映射中的int和string对时遇到问题: 这是我使用的代码: #include <iostream> #include <utility> #include <map> using namespace std; typedef map<int,string> intID; int main(){ intID ID; ID.insert(pair<int,string>(123,"studentn

我在试图打印STL映射中的int和string对时遇到问题:

这是我使用的代码:

#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;
    }
}
#包括
#包括
#包括
使用名称空间std;
typedef映射intID;
int main(){
intID;
ID.插入(成对(123,“学生姓名1”);
ID.插入(成对(124,“学生姓名2”);
ID.插入(成对(122,“学生姓名3”);
intID::迭代器IDIter;
对于(IDIter=ID.begin();IDIter!=ID.end();++IDIter){

cout您需要包含
标题。您只能通过从其他标题附带包含的方式使用
std::string
类型。您不能依赖于此。包含
还会带来
操作符的重载您需要包含
标题。您只能使用
std::string
通过从其他头中附带包含的方式键入。你不能依赖于此。包含
也会带来
运算符的重载。我认为,你还应该包含
,因为
只定义
std::cout
而不是它的成员。但是,当实现需要lpfully include
@msa中的
会更改
运算符true的
std::string
重载。但自从上次使用重载后,我写了“还包括ostream”(
我认为,您还应该包括
,因为
只定义
std::cout
,而不定义其成员。但是,当实现在
@msa中有效地包含
时,您通常可以避免
运算符true的
std::string
重载。但是我写了“还包括ostream”自上次使用重载(