Click here to Skip to main content
16,006,001 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhow to set a bitmap as the background of ricdedit control? Pin
boyboy7-Oct-04 13:49
boyboy7-Oct-04 13:49 
AnswerRe: how to set a bitmap as the background of ricdedit control? Pin
Anonymous9-Oct-04 15:10
Anonymous9-Oct-04 15:10 
GeneralMortgage Amortization Pin
sweetlady7-Oct-04 13:44
sweetlady7-Oct-04 13:44 
GeneralRe: Mortgage Amortization Pin
Colin Angus Mackay7-Oct-04 14:13
Colin Angus Mackay7-Oct-04 14:13 
GeneralRe: Mortgage Amortization Pin
2249177-Oct-04 21:19
2249177-Oct-04 21:19 
GeneralDouble Sorting Pin
Kurt _B7-Oct-04 12:57
Kurt _B7-Oct-04 12:57 
GeneralRe: Double Sorting Pin
Ryan Binns7-Oct-04 18:10
Ryan Binns7-Oct-04 18:10 
GeneralRe: Double Sorting Pin
Kevin McFarlane7-Oct-04 23:51
Kevin McFarlane7-Oct-04 23:51 
Try this...

#include <afxtempl.h>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

struct Person
{
Person(const CString& n = "", int a = 0) : name(n), age(a) {}
CString name;
int age;
};

class ComparePerson : public binary_function<Person, Person, bool>
{
public:
// Sort by name and then age
bool operator()(const Person& first, const Person& second) const
{ return first.name < second.name || (first.name == second.name && first.age < second.age); }
};

void SortTest()
{
CArray<Person, Person> person;
person.Add(Person("Kevin", 30));
person.Add(Person("Gary", 24));
person.Add(Person("Peter", 36));
person.Add(Person("Peter", 16));
person.Add(Person("Richard", 19));
person.Add(Person("Joanne", 40));

int count = person.GetSize();

afxDump << "Initial contents\n";

for (int i = 0; i < count; i++)
{
afxDump << "name = " << person[i].name << ", " << "age = " << person[i].age << "\n";
}

// Last Person

Person* begin = person.GetData();
Person* end = begin + count;

afxDump << "Last Person \n";
Person* last = max_element(begin, end, ComparePerson());
afxDump << "Last Person: " << "name = " << last->name << ", " << "age = " << last->age << "\n";
afxDump << "\n";

// Sort
sort(begin, end, ComparePerson());

afxDump << "Sorted persons\n";

for (i = 0; i < count; i++)
{
afxDump << "name = " << person[i].name << ", " << "age = " << person[i].age << "\n";
}

}

Output

Sorted persons
name = Gary, age = 24
name = Joanne, age = 40
name = Kevin, age = 30
name = Peter, age = 16
name = Peter, age = 36
name = Richard, age = 19

Is this what you want?

Kevin
Generalb-tree Pin
nordyck7-Oct-04 12:25
nordyck7-Oct-04 12:25 
GeneralFirewalled 2 Firewalled Connection like Torrent Pin
ffer7-Oct-04 12:09
ffer7-Oct-04 12:09 
Generalpassing object to create linked list Pin
lordmickel7-Oct-04 9:28
lordmickel7-Oct-04 9:28 
GeneralRe: passing object to create linked list Pin
Joaquín M López Muñoz7-Oct-04 9:42
Joaquín M López Muñoz7-Oct-04 9:42 
GeneralRe: passing object to create linked list Pin
lordmickel7-Oct-04 9:57
lordmickel7-Oct-04 9:57 
GeneralPassing parameters to threads Pin
Nikhil Wason7-Oct-04 9:15
Nikhil Wason7-Oct-04 9:15 
GeneralRe: Passing parameters to threads Pin
Joaquín M López Muñoz7-Oct-04 9:50
Joaquín M López Muñoz7-Oct-04 9:50 
GeneralRe: Passing parameters to threads Pin
Anonymous9-Oct-04 15:21
Anonymous9-Oct-04 15:21 
QuestionPossible to write .ini from .bat? Pin
blueSprite7-Oct-04 9:08
blueSprite7-Oct-04 9:08 
AnswerRe: Possible to write .ini from .bat? Pin
Joaquín M López Muñoz7-Oct-04 9:59
Joaquín M López Muñoz7-Oct-04 9:59 
AnswerRe: Possible to write .ini from .bat? Pin
pbloechl7-Oct-04 10:00
pbloechl7-Oct-04 10:00 
AnswerRe: Possible to write .ini from .bat? Pin
blueSprite7-Oct-04 10:34
blueSprite7-Oct-04 10:34 
GeneralMFC fails to create main CFrameWnd Pin
Vaclav7-Oct-04 8:17
Vaclav7-Oct-04 8:17 
GeneralRe: MFC fails to create main CFrameWnd Pin
David Crow7-Oct-04 9:05
David Crow7-Oct-04 9:05 
GeneralRe: MFC fails to create main CFrameWnd found casue - now what? Pin
Vaclav8-Oct-04 10:16
Vaclav8-Oct-04 10:16 
QuestionHow to inlude files,getting link error! Pin
Dani1000017-Oct-04 7:11
Dani1000017-Oct-04 7:11 
AnswerRe: How to inlude files,getting link error! Pin
Rage7-Oct-04 7:42
professionalRage7-Oct-04 7:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.