Hi - I've can see there is other people playing around with vectors and structures in the forum - hopefully someone knows how to do this.

I have a vector of structs, and I want to sort it by 'Title' (Alphabetically)

- Is it even possible to sort a vector of structs with standard sort?
or do i have to use a map and sort it by keys ? if so, how do I create a map of structs ?

Thanks in advance

struct Test
{
    std::string Title;
    std::string ISBN;
    int shelf;
};

int main(int argc, char *argv[])
{

vector <Test> MyVec;

// MyVec.Push_Back(something) - Left out

sort(MyVec.begin(), MyVec.end()); // Dosn't work
}

EDIT:
It looks like it can be done with a comparison function; However i have no clue on how to make such a function - i'm fairly new to c++.

sort(MyVec.begin(), MyVec.end(), ComparisonFunction);

Regards Kasper

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.