使用cin在C ++中将元素插入到地图中

时间:2017-12-11 16:18:25

标签: c++

我不知道如何使用cin将数据插入地图。

我认为它应该是这样的:

for(int i=0; i<=N;i++){
    mapas.insert ( '/*word from cin*/',i );
    /*or*/
    mapas[/*word from cin*/]=i;
  }

这是我的完整代码:

#include <iostream>
#include<algorithm>
#include <string>
#include <map>

using namespace std;

int main() {

  map<string,int>mapas; 
  map<string,int>::iterator it;
  int N;//how many words there will be
  string zodis;//the word I will be looking for later
  cin>>N;
  cin>>zodis;




  for(it=mapas.begin();it!=mapas.end();it++){
    cout<<it->first<<endl;}

  }

任何想法都会受到赞赏,因为我要杀了自己

1 个答案:

答案 0 :(得分:0)

你需要

mapas[<string>] = <int>;

如,

mapas[zodis] = N;