maps with list iteration

Hello guys, got stuck in below :(

i have a map called
1
2
list<string> list1;
map<string,list>map1;

i want to populate my map while reading some data (strings)

and this is not the case for using push_back for iterating the list.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
map1 m1;
list1 l1;

while ((dir = readdir(some_path)) != NULL) {

		snprintf(buf, sizeof(buf) -1, "%s/%s",some_path, dir->d_name);
		
          /*        .......
                some code 
                ........
          */         
	        file = fopen(buf, "r");
		if (file != NULL) {
			while (fgets(buf, sizeof(buf), file) != NULL) {

			//	Here need to store in map 
				m1[buf]=list1(dir->d_name); //Here storing into map  ,
   //   folder in which specified path need to store in list
    //                and data in file will store in map . 
                          }
}



Any help would be greatly appreciated.
Last edited on
I don't understand the problem.
It's hard to tell but I think you want
map<string, list<string> > map1;
and then line 17 becomes m1[buf].push_back(dir->d_name);
It was a bit confused that time, here is the explanation,

I have some directories and i want to maintain the database using map.

Here, i m trying to read the strings in a file and the file was existed in directory.

Ex: f1 is a name of file existed in d1 ( directory )
f1 contains strings which are specified in each line
abcdf
afafete
coder777
dhayden
...
...
and so on

the same file f1 is located in every directory like d2, d3 ..and so on

i want to maintain the database like strings are my key value and directories are my mapped value .

purpose : I want to know what are the similar strings which are existed in files under different directories in a one shot display.

no problem with display the prob is storing into map ..line 17 in above code.



Hope i explained better now.




I think the way I suggested would work. The key is a string and the value is a list of directories.
Topic archived. No new replies allowed.