Click here to Skip to main content
15,905,316 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Ending Thread Problems Pin
tbrake23-Feb-06 14:17
tbrake23-Feb-06 14:17 
GeneralRe: Ending Thread Problems Pin
Ryan Binns23-Feb-06 14:50
Ryan Binns23-Feb-06 14:50 
GeneralRe: Ending Thread Problems Pin
Blake Miller24-Feb-06 5:26
Blake Miller24-Feb-06 5:26 
QuestionHow to display the value of a variable in a MessageBox? Pin
vinceher23-Feb-06 10:18
vinceher23-Feb-06 10:18 
AnswerRe: How to display the value of a variable in a MessageBox? Pin
David Crow23-Feb-06 10:31
David Crow23-Feb-06 10:31 
AnswerRe: How to display the value of a variable in a MessageBox? Pin
Stephen Hewitt23-Feb-06 10:45
Stephen Hewitt23-Feb-06 10:45 
GeneralRe: How to display the value of a variable in a MessageBox? Pin
vinceher23-Feb-06 13:27
vinceher23-Feb-06 13:27 
GeneralRe: How to display the value of a variable in a MessageBox? Pin
Stephen Hewitt23-Feb-06 13:34
Stephen Hewitt23-Feb-06 13:34 
GeneralRe: How to display the value of a variable in a MessageBox? Pin
Wim Engberts23-Feb-06 23:21
Wim Engberts23-Feb-06 23:21 
QuestionInfo about Digital image watermarking in the Wavelet transform domain ? Pin
Loay Al Lusi23-Feb-06 9:36
Loay Al Lusi23-Feb-06 9:36 
AnswerRe: Info about Digital image watermarking in the Wavelet transform domain ? Pin
Stephen Hewitt23-Feb-06 19:16
Stephen Hewitt23-Feb-06 19:16 
AnswerRe: Info about Digital image watermarking in the Wavelet transform domain ? Pin
Cool Ju23-Feb-06 20:01
Cool Ju23-Feb-06 20:01 
QuestionSorting items, specifying multiple parameters Pin
Gunn31723-Feb-06 9:25
Gunn31723-Feb-06 9:25 
AnswerRe: Sorting items, specifying multiple parameters Pin
David Crow23-Feb-06 9:35
David Crow23-Feb-06 9:35 
GeneralRe: Sorting items, specifying multiple parameters Pin
Gunn31723-Feb-06 10:15
Gunn31723-Feb-06 10:15 
GeneralRe: Sorting items, specifying multiple parameters Pin
David Crow23-Feb-06 10:30
David Crow23-Feb-06 10:30 
AnswerRe: Sorting items, specifying multiple parameters Pin
Chris Losinger23-Feb-06 9:38
professionalChris Losinger23-Feb-06 9:38 
GeneralRe: Sorting items, specifying multiple parameters Pin
Gunn31723-Feb-06 10:11
Gunn31723-Feb-06 10:11 
GeneralRe: Sorting items, specifying multiple parameters Pin
Chris Losinger23-Feb-06 10:28
professionalChris Losinger23-Feb-06 10:28 
GeneralRe: Sorting items, specifying multiple parameters Pin
Gunn31723-Feb-06 11:08
Gunn31723-Feb-06 11:08 
GeneralRe: Sorting items, specifying multiple parameters Pin
Chris Losinger23-Feb-06 11:17
professionalChris Losinger23-Feb-06 11:17 
AnswerRe: Sorting items, specifying multiple parameters Pin
Stephen Hewitt23-Feb-06 11:20
Stephen Hewitt23-Feb-06 11:20 
Using qsort is old fashioned, you should be using STL - it's faster safer and more flexible. Here's how I'd do it:
----------

#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;

// Our data.
struct Blah
{
Blah(int Type, const char* pName) :
m_Type(Type), m_pName(pName)
{
}

int m_Type;
const char* m_pName;
};

// Print out a blah.
ostream& operator<<(ostream& s, const Blah& b)
{
s << "Type: " << b.m_Type << ", Name: \"" << b.m_pName << "\"";
return s;
}

// Sort functors.
struct SortByType
{
bool operator()(const Blah& l, const Blah& r) const
{
return l.m_Type < r.m_Type;
}
};

struct SortByName
{
bool operator()(const Blah& l, const Blah& r) const
{
return strcmp(l.m_pName, r.m_pName) < 0;
}
};

struct SortByTypeThenName
{
bool operator()(const Blah& l, const Blah& r) const
{
return SortByType()(l, r) | (!SortByType()(r, l) && SortByName()(l, r));
}
};

// The data.
Blah g_Blahs[] =
{
Blah(1, "George"), Blah(2, "Liam"), Blah(2, "Hank"),
Blah(0, "Abigail"), Blah(1, "Bob"), Blah(0, "Jessica"),
Blah(2, "Con"), Blah(1, "Kyle"), Blah(0, "Faye")
};

int main(int argc, char* argv[])
{
Blah* pBegin = &g_Blahs[0];
Blah* pEnd = &g_Blahs[sizeof(g_Blahs)/sizeof(g_Blahs[0])];
ostream_iterator<Blah> oi(cout, "\n");

// Sort by type.
cout << "Type:\n";
sort(pBegin, pEnd, SortByType());
copy(pBegin, pEnd, oi);
cout << "\n";

// Sort by name.
cout << "Name:\n";
sort(pBegin, pEnd, SortByName());
copy(pBegin, pEnd, oi);
cout << "\n";

// Sort by type and name.
cout << "Type and name:\n";
sort(pBegin, pEnd, SortByTypeThenName());
copy(pBegin, pEnd, oi);
cout << "\n";

return 0;
}


Steve

-- modified at 17:29 Thursday 23rd February, 2006
FIXED error in SortByTypeThenName.

GeneralRe: Sorting items, specifying multiple parameters Pin
Gunn31728-Feb-06 2:40
Gunn31728-Feb-06 2:40 
QuestionVisual Studio 6.0 with other compliers Pin
softwaremonkey23-Feb-06 8:21
softwaremonkey23-Feb-06 8:21 
AnswerRe: Visual Studio 6.0 with other compliers Pin
basementman23-Feb-06 8:34
basementman23-Feb-06 8:34 

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.