Originally Posted by
Nwb
Umgh yes the number is like the ID of the string.
"So you define these Things" - sorry what do I define? I don't know how to define a structure at run time can you give me an example? And I'm pretty much blanking after that line..
You can't, but that's okay, because you don't want to. The object is the pair of <id, string> and that's defined right now, not at run time. How were you planning to handle the unknown number of things before? In a vector (well, a pair of vectors). The vectors deal with the quantity of things; the object deals with the relationship between the id and the string.
Code:
struct Thing {
int id;
std::string name;
};
bool compare_the_things(const Thing &a, const Thing &b) {
return a.id > b.id;
}
int main(void) {
std::vector<Thing> pile_of_things;
//however your info is stored you'll have to build the vector
while(still things to read) {
Thing temp;
read in data to temp;
pile_of_things.push_back(temp);
}
//now sort the things
std::sort(pile_of_things.begin(), pile_of_things.end(), compare_the_things);
//then you can walk through the list
}