지도에서 키와 값을 인쇄하려고합니다. 콘솔에서 출력을 얻지 못해서 무엇이 빠졌는지 모르겠습니다. 따라서 뭔가 잘못되었습니다.std :: map 인쇄하기
#include <iostream>
#include <map>
using namespace std;
typedef map<string, int> employees;
int main(void)
{
employees object;
employees ref;
employees &m = ref;
employees::const_iterator it;
object["GREG"] = 1000;
object["ROBERT"] = 2000;
for(it = m.begin(); it != m.end(); ++it)
{
cout << "Key" << it->first << "Key value: " << it->second << endl;
}
}
나는 직원이라는 MAP에 대한 참조로 엉망 수있는 한 추측, 아마도 내가 어쩌면 덜 '바보, 어떻게 든 중 하나가 작동하지 않는 (이 솔루션을 시도해야 ... 그러나한다 접근 ') :
for(it = employees.begin(), it != employees.end(), ++it)
{
employees::const_iterator it;
}
'ref [ "GREG"] = 1000; ref [ "ROBERT"] = 2000;'' –
'#include'이 필요합니다. –
juanchopanza
ref에 값을 추가하지만 비어있는 인쇄 객체 –