C++,迭代器问题

标签 c++ iterator

map <int, char*> testmap;
testmap[1] = "123";
testmap[2] = "007";
map<int, char*>::iterator p;

for(p = my_map.begin(); p != my_map.end(); p++) {
int len = strlen(p); // error here, why? thanks
cout << len << endl;
  cout << p->first << " : ";
  cout << p->second << endl;
}

我在这个谎言上出错了:int len = strlen(p),我想得到数组的长度。如何修复它? 谢谢!

最佳答案

我猜你的意思是

strlen(p->second);

关于C++,迭代器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4864902/

相关文章:

c++ - 如何在两个成员函数之间共享一个 QListIterator?

rust - 如何实现一个委托(delegate)给 HashMap::values() 的迭代器

c++ - 如何构建在所有机器上表现相同的 exe

c++ - 通用树的析构函数

c++ - 使用 std::ofstream 在 C++ 中格式化浮点变量输出

c++ - 在 Visual Studio 2013 中自动 c++ 源代码格式化

C++列表迭代器算术替换思路

c++ - 类成员 vector 上的迭代器未正确取消引用

c# - 为什么在 C# 中进行基于模式的编程

c++ - C 和 C++ 的效率