I have a structure type like the one shown below, I use it to store the output of my program and these structures are stored in a structure vector.
Now I would like to print out the structures stored in the vector in ascending order of int Time_IF.

struct Input
{
 int Inst;
 string Instline;
 string DestReg;
 string InputReg1;
 string InputReg2;
 int Time_IF;
 int Time_ID;
};

I tried printing them out by comparing

while(OutputBuffer.size())
{
    for(int i=0; i<OutputBuffer.size()-1; i++)
       {        if(OutputBuffer[Outputval].Time_IF>OutputBuffer[i+1].Time_IF)
                        Outputval=i+1;}
}

to get the index and then i would print out the respective value

    Outfile<<setw(40)<<OutputBuffer[Outputval].Instline;

erase the printed structure from the vector

OutputBuffer.erase (OutputBuffer.begin()+Outputval);
reset outputval=0

but i find that some of the structures do not get printed..in this method..
is there a better way of sorting a structure vector based on a parameter in the structure...?

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.