Hi,
I am new to C++ and trying to use map in C++.
I have a sample program as shown below-
#include <iostream>
#include <map>
using namespace std;
int main()
{
map<char*, char*> m;
int i;
char name[64];
char val[64];
// put pairs into map
for(i=0; i<26; i++) {
sprintf(name, "Hello%d",i);
sprintf(val, "There%d",i);
m.insert(pair<char*, char*>((char*)name, (char*)val));
}
for(map<char*, char*>::iterator p = m.begin(); p!= m.end(); ++p) {
cout << p->first << ": " << p->second << endl;
}
return 0;
}
I expect this program to print thge output as below-
Hello0: There0
Hello1: There1
Hello2: There2
.
.
.
Hello25: There25
But the only output from this program is -
Hello25: There25
Can somebody help me achieving the required output. The re-requisite is to have key and value both as char*
data.
Thanks in advance.
Shubhendu