求大佬们纠正bug!
利用map类写了一个简单的代码。功能是对于10个字符串,输出每种字符串和对应的个数。
但是vs2010,vs2017都运行不了,中间有报错。哪里错了?
#include "stdafx.h"
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <map>
#include <iostream>
using namespace std;
int main()
{
string s[10];
int i;
s[0] = "wfe";
s[1] = "sdf";
s[2] = "sahf";
s[3] = "sdf";
s[4] = "sdf";
s[5] = "wfe";
s[6] = "sdf";
s[7] = "r";
s[8] = "bfs";
s[9] = "trnd";
map<string,int>mci;
for (int i=0;i<10;i++)
{
if (mci.find(s[i]) == mci.end())
mci[s[i]]=1;
else
++mci[s[i]];
}
for(map<string,int>::iterator iter;iter != mci.end(); ++iter)
cout << (*iter).first << " " << (*iter).second << endl;
scanf ("%d",&i);
return 0;
}