it.first로 인쇄하려고하면 두 번째로 작동하지 않습니다. 이것도 유효한 기능입니까?지도에서 키와 값을 모두 인쇄하는 방법은 무엇입니까?
cout << it->first << ":" << it->second << endl;
주없이 괄호, 그 함수 호출되지 않습니다
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
map<string, int> workers;
workers["John"] = 1;
workers["Frank"] = 2;
for(map<string, int>::iterator it = workers.begin(); it != workers.end(); ++it) {
cout<<it.first()<<":"<<it.second()<<endl;
}
return 0;
}
죄송합니다. 잘못 입력했거나 1 단계 또는 2 단계 모두 작동하지 않습니다. 어떻게지도를 인쇄하나요? –