【发布时间】:2011-06-03 20:50:51
【问题描述】:
我已经声明了一个关联数组,现在想打印它:
#include <map>
#include <string>
#include <cstdio>
using namespace std;
int main() {
map<string, int> m;
m["Peter"] = 4;
m["John"] = 3;
m["Katie"] = 3;
map<string, int>::iterator curr,end;
for(curr = m.begin(), end = m.end(); curr != end; curr++) {
printf("%s : %i\n", curr->first, curr->second);
}
return 0;
}
我的编译器出现错误:
main.cpp: In function ‘int main()’:
main.cpp:24: warning: cannot pass objects of non-POD type ‘const struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ through ‘...’; call will abort at runtime
还有惊喜 - 这是真的 - 在运行时调用中止......
但我不知道为什么...我应该解决什么问题? “通过‘...’”到底是什么意思?
【问题讨论】:
标签: c++ arrays associative-array