Results 1 to 5 of 5

Thread: Help sorting a vector/map ....

  1. #1
    Join Date
    Sep 2004
    Posts
    2,461

    Default Help sorting a vector/map ....

    i have a vector of structs ...

    Code:
    struct filestore
    {
        string filename;
        int wordcount;
    };
    
    vector <filestore> filesortlist;

    now i want to sort them by the wordcount value in desecending order

    whats wrong with this

    Code:
    std::sort(filesortlist.begin(), filesortlist.end());

  2. #2
    Join Date
    Sep 2004
    Posts
    2,461

    Default

    any help? its a compile time error being triggered in a header file.

  3. #3
    Join Date
    Jan 2009
    Posts
    2,215
    Country
    United States

    Default

    I have the experience that the header file is NEVER wrong (for some reason). Recheck any code relating to the header file, along with lines before it. What kind of error are you getting?
    Rooted HTC Amaze 4G, Android 4.1.2 PA/AOKP/CM10 on teifin' AT&T's network; Rooted ASUS Transformer TF101 w/ dock, Android 4.0.3 Android Revolution HD; Laptop: HP HDX, 2.13GHzx2, 4GB, 128GB SSD, 1TB xHDD, Win7
    Facebook page: Skeleville Software Solutions

  4. #4
    Join Date
    Sep 2004
    Posts
    2,461

    Default

    Code:
    2472 C:\Dev-Cpp\include\c++\3.4.2\bits\stl_algo.h   instantiated from `void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<filestore*, std::vector<filestore, std::allocator<filestore> > >, _Size = int]'

  5. #5
    Join Date
    Dec 2002
    Posts
    500

    Default

    i dont think sort knows how to compare the elements of the vector/list.

    you need to create a comparator or something like that.
    a compare function, and either make it globally accessible or otherwise indicate that the sort routine should use it.
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •