1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Vector of structs? C++

Discussion in 'Programming & Webmastering' started by [I.R.A]_FBi, Mar 24, 2009.

  1. [I.R.A]_FBi

    [I.R.A]_FBi New Member

    Joined:
    May 19, 2007
    Messages:
    7,664 (2.79/day)
    Thanks Received:
    540
    Location:
    c:\programs\kitteh.exe
    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)

    Code:
    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
     
  2. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,963 (6.24/day)
    Thanks Received:
    3,803
    Location:
    IA, USA
    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).
     
    Crunching for Team TPU
  3. [I.R.A]_FBi

    [I.R.A]_FBi New Member

    Joined:
    May 19, 2007
    Messages:
    7,664 (2.79/day)
    Thanks Received:
    540
    Location:
    c:\programs\kitteh.exe
    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
     
  4. [I.R.A]_FBi

    [I.R.A]_FBi New Member

    Joined:
    May 19, 2007
    Messages:
    7,664 (2.79/day)
    Thanks Received:
    540
    Location:
    c:\programs\kitteh.exe
    navigating and sorting maps (c++)

    i want to do the equivalent of this
    Code:
    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

    Code:
    
    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
     
    Last edited: Mar 26, 2009
  5. [I.R.A]_FBi

    [I.R.A]_FBi New Member

    Joined:
    May 19, 2007
    Messages:
    7,664 (2.79/day)
    Thanks Received:
    540
    Location:
    c:\programs\kitteh.exe
    anyone?
     

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page