You need a custom functor to compare your attempts. This should do the trick:
#include <algorithm>
#include <vector>
struct sorthelper : public std::binary_function<try_, try_, bool>
{
inline bool operator()(const try_& left, const try_& right)
{ return left.id < right.id; }
};
...
std::vector<try_> v;
std::sort(v.begin(), v.end(), sorthelper());
...
Please feel free to ask if you have any further questions. Do you have a Stroustrup book?
Edit: Matteo's suggestion:
struct try_
{
int id;
string val;
bool operator<(const try_& other) const
{return id < other.id;}
};
...
std::vector<try_> v;
std::sort(v.begin(), v.end());
...