我的問題與this one幾乎完全相同,但是那裏的解決方案還沒有解決我的錯誤。無法迭代std :: map使用std :: string作爲鍵
在main.h
我:
#include <map>
#include <string>
std::map<std::string, int64_t> receive_times;
而且在main.cpp
:
std::map<std::string, int64_t>::const_iterator iter;
std::map<std::string, int64_t>::const_iterator eiter = receive_times.end();
for (iter = receive_times.begin(); iter < eiter; ++iter)
printf("%s: %ld\n", iter->first.c_str(), iter->second);
然而,當我嘗試編譯我收到以下錯誤:
error: invalid operands to binary expression ('std::map<std::string, int64_t>::const_iterator' (aka '_Rb_tree_const_iterator<value_type>') and 'std::map<std::string, int64_t>::const_iterator'
(aka '_Rb_tree_const_iterator<value_type>'))
for (iter = receive_times.begin(); iter < eiter; ++iter)
~~~~^~~~~~
的解決方案我在頂部鏈接的問題是因爲缺少#include <string>
,但顯然我已包括在內。任何提示?
您不應該在頭文件中定義變量... –