1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
int main() {
map<char*,char*>M;
ifstream readFile;
readFile.open("textfile.txt");
if (readFile.is_open()) {
char *p;
string str;
char buf[100];
while (!readFile.eof()) {
getline(readFile,str);
strcpy(buf, str.c_str());
char a[10];
char b[16];
memset(a,NULL,10);
memset(b,NULL,16);
p = strtok(buf," \t");
while(p != NULL) {
strcpy(a,p);
p = strtok(NULL, " \t");
strcpy(b,p);
M.insert(pair<char*,char*>(a,b)); //does not work
p = strtok(NULL, " \t");
}
}
}
cout<<"--------------"<<endl;
char a[10] ;
char b[10] ;
char *p1 = "Hello";
char *p2 = "World";
strcpy(a,p1);
strcpy(b,p2);
M.insert(pair<char*,char*>(a,b)); //Does Work
map<char*,char*>::iterator it;
for (it = M.begin(); it!=M.end();it++){
cout<<(*it).first<<" "<<(*it).second<<endl;
}
return 0;
}
| |