我写了一个程序,它会读取输入,直到你点击“,”——输入处的昏迷。然后它会计算你输入的字母数量,
我想遍历这张地图,但它说 it
不能在没有类型的情况下定义:
#include <iostream>
#include <conio.h>
#include <ctype.h>
#include <iostream>
#include <string>
#include <tr1/unordered_map>
using namespace std;
int main(){
cout << "Type '.' when finished typing keys: " << endl;
char ch;
int n = 128;
std::tr1::unordered_map <char, int> map;
do{
ch = _getch();
cout << ch;
if(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z'){
map[ch] = map[ch] + 1;
}
} while( ch != '.' );
cout << endl;
for ( auto it = map.begin(); it != map.end(); ++it ) //ERROR HERE
cout << " " << it->first << ":" << it->second;
return 0;
}
原文由 Yoda 发布,翻译遵循 CC BY-SA 4.0 许可协议
根据 Dorin Lazăr 的回答,另一种可能的解决方案是: