# Vector of structs? C++



## [I.R.A]_FBi (Mar 24, 2009)

Im writing a sort program with a vector i want to sort (which is to store some items which i counted previosly and the name its assigned to, search engine type thing)


```
struct filestore
{
    string filename;
    int wordcount;
}

vector <filestore> filesortlist;
```

my problem is how do i now assign something, i want to load in the details, to i create a temporary filestore struct to hold it then i pop back or is there something more elegant?

al


----------



## FordGT90Concept (Mar 25, 2009)

A vector of structs is no different from a vector of strings except in what each index of the vector contains (an instance of your struct instead of an instance of a string).


----------



## [I.R.A]_FBi (Mar 25, 2009)

what i was doing is storing  list of file snad the amount of hits in them, ive been instructed to use a map ... now i need to read and get back to you guys if i dont understand


----------



## [I.R.A]_FBi (Mar 26, 2009)

*navigating and sorting maps (c++)*

i want to do the equivalent of this 
	
	



```
int i,j;
    for(i=0;i<10;i++)
    {
        for(j=0;j<i;j++)
        {
            if(array[i]<array[j])
            {
                int temp=array[i]; //swap 
                array[i]=array[j];
                array[j]=temp;
            }

        }

    }
```

with maps


```
map <string, int> m1;
map <string, int>::iterator pos;

for(pos = m1.begin(); pos!= m1.end(); ++pos)
    {
        for(pos = m1.begin(); pos!= m1.end(); ++pos)
        {
             //lost?
    }

}
```

im sorting by the int


----------



## [I.R.A]_FBi (Mar 27, 2009)

anyone?


----------

