// constructing maps
#include <iostream>
#include <map>
using namespace std;
int main()
{
std::map<string, int> myMap;
myMap["first"] = 10;
myMap["second"] = 30;
myMap["third"] = 50;
myMap["fourth"] = 70;
for (map<string, int>::iterator it = myMap.begin();
it != myMap.end(); it++)
{
cout << it->first.c_str() << " " << it->second << endl;//函数c_str()就是将C++的string转化为C的字符串数组,c_str()生成一个const char *指针,指向字符串的首地址。
}
return 0;
}

1万+

被折叠的 条评论
为什么被折叠?



