C++ STL 映射错误:命名空间“std”中没有名为“map”的模板;您指的是 'max' 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20585332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
STL map error: no template named 'map' in namespace 'std'; did you mean 'max'?
提问by Hymanie
I am working on an application that tracks the frequency of letters in a string. To do this I created the following Struct
我正在开发一个跟踪字符串中字母频率的应用程序。为此,我创建了以下结构
struct MessageLetter{
char letter;
int count;
MessageLetter(char letter, int freq)
: letter(letter), count(freq)
{}
};
Now I am trying to create a stl::map like follows...
现在我正在尝试创建一个 stl::map 如下...
std::map<std::string, MessageLetter> lList;
for(int i = 0; i < output.length(); i++){
std::cout << i << output[i] << std::endl;
if(lList.find(output[i]) == lList.end()){
std::cout << "Letter not found" << std::endl;
MessageLetter m = {output[i],1};
lList[output[i]] = m;
}
else{
std::cout << "Letter found" << std::endl;
}
}
When I try to compile this I get the following...
当我尝试编译它时,我得到以下信息......
test.cpp:95:8: error: no template named 'map' in namespace 'std'; did you mean 'max'?
std::map<std::string, MessageLetter> lList;
I am new to c++ so any guidance would be great. And if this is a duplicate I will be happy to remove. Any other information (C++ version etc) will be provided if needed. This is eventually going to be a native Android app.
我是 C++ 的新手,所以任何指导都会很棒。如果这是重复的,我很乐意删除。如果需要,将提供任何其他信息(C++ 版本等)。这最终将成为一个原生的 Android 应用程序。
回答by
#include <map>
Problem solved.
问题解决了。