我想插入段落或文章内容并处理每个单词。下面我试图获取每个字符串,然后得到它的出现。最后,我想要出现次数最多的单词。我是 C++ 新手。现在我已经静态插入了两个字符串。这给出了错误expected primary-expression before ‘.’ token
。代码如下:`
#include <string>
#include <iostream>
#include <unordered_map>
int main()
{
typedef std::unordered_map<std::string,int> occurrences;
occurrences s1;
s1.insert(std::pair<std::string,int>("Hello",1));
s1.insert(std::pair<std::string,int>("Hellos",2));
//for ( auto it = occurrences.begin(); it != occurrences.end(); ++it ) this also gives same + additional " error: unable to deduce ‘auto’ from ‘<expression error>’" error
for (std::unordered_map<std::string, int>::iterator it = occurrences.begin();//Error is here
it != occurrences.end(); ////Error is here
++it)
{
std::cout << "words :" << it->first << "occured" << it->second << "times";
}
return 0;
}
错误在哪里?