Click here to Skip to main content
15,922,166 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Initialization part in SDI MFC project. Pin
tingu21-Jun-06 4:44
tingu21-Jun-06 4:44 
GeneralRe: Initialization part in SDI MFC project. Pin
David Crow21-Jun-06 4:49
David Crow21-Jun-06 4:49 
AnswerRe: Initialization part in SDI MFC project. Pin
Viorel.21-Jun-06 4:36
Viorel.21-Jun-06 4:36 
QuestionSort an std::vector?! [modified] Pin
bosfan21-Jun-06 4:11
bosfan21-Jun-06 4:11 
AnswerRe: Sort an std::vector?! Pin
toxcct21-Jun-06 4:19
toxcct21-Jun-06 4:19 
AnswerRe: Sort an std::vector?! Pin
Chris Losinger21-Jun-06 4:20
professionalChris Losinger21-Jun-06 4:20 
GeneralRe: Sort an std::vector?! [modified] Pin
bosfan21-Jun-06 4:31
bosfan21-Jun-06 4:31 
GeneralRe: Sort an std::vector?! [modified] Pin
Chris Losinger21-Jun-06 4:45
professionalChris Losinger21-Jun-06 4:45 
if i run your code (with minor adjustments to make it compile - and fill with random data), it works fine - they are sorted by index:

class CVector
{
public:
	CString csIndex;
	CString csUrl;
	UINT iIndex;  

	CVector(int i, char *a, char *b)
	{
		iIndex = i;
		csIndex = a;
		csUrl = b;
	}
};

// this two functions are global
bool operator==(const CVector& x, const CVector& y)
{
	return (x.csUrl == y.csUrl) && (x.iIndex == y.iIndex);
}

// IDs will be sorted by Score, not by Name.
bool operator<(const CVector& x, const CVector& y)
{
	return x.iIndex < y.iIndex;
}
  
  
.... main
  
  
	// Global definition:
	typedef vector < CVector > VectorGlobal;
	VectorGlobal vec;
	
	// in function:
	// in an iteration i fill the vec with data
	// example while!
	int int_value = 0;
	while(int_value < 10)
	{
		char a[2];
		a[0] = 'a' + (rand() % 26);
		char b[2];
		b[0]= 'A' + (rand() % 26);
		a[1]=b[1]=0;
		vec.push_back(CVector(rand() % 40, a, b));
		int_value++;
	}
	
	// after this i call the sort-function and check if any data stored in vec:
	VectorGlobal::iterator iter;
	
	for(iter = vec.begin(); iter != vec.end(); iter++)
	{
		TRACE("CSindex: %s, Url: %s   Idx: %d\n", iter->csIndex, iter->csUrl, iter->iIndex);
	}
	sort(vec.begin(), vec.end());
	
	for(iter = vec.begin(); iter != vec.end(); iter++)
	{
		TRACE("CSindex: %s, Url: %s   Idx: %d\n", iter->csIndex, iter->csUrl, iter->iIndex);
	}
	// here is end of fill data in an vector, no debugger errors!


output:

CSindex: p, Url: H Idx: 14
CSindex: g, Url: H Idx: 4
CSindex: m, Url: E Idx: 2
CSindex: y, Url: L Idx: 25
CSindex: l, Url: F Idx: 1
CSindex: x, Url: F Idx: 22
CSindex: r, Url: C Idx: 31
CSindex: s, Url: C Idx: 33
CSindex: g, Url: G Idx: 21
CSindex: w, Url: K Idx: 15

CSindex: l, Url: F Idx: 1
CSindex: m, Url: E Idx: 2
CSindex: g, Url: H Idx: 4
CSindex: p, Url: H Idx: 14
CSindex: w, Url: K Idx: 15
CSindex: g, Url: G Idx: 21
CSindex: x, Url: F Idx: 22
CSindex: y, Url: L Idx: 25
CSindex: r, Url: C Idx: 31
CSindex: s, Url: C Idx: 33


Cleek | Image Toolkits | Thumbnail maker


-- modified at 10:48 Wednesday 21st June, 2006
GeneralRe: Sort an std::vector?! Pin
bosfan21-Jun-06 5:00
bosfan21-Jun-06 5:00 
AnswerRe: Sort an std::vector?! Pin
Zac Howland21-Jun-06 4:30
Zac Howland21-Jun-06 4:30 
GeneralRe: Sort an std::vector?! [modified] Pin
bosfan21-Jun-06 4:38
bosfan21-Jun-06 4:38 
AnswerRe: Sort an std::vector?! Pin
FarPointer21-Jun-06 4:36
FarPointer21-Jun-06 4:36 
AnswerRe: Sort an std::vector?! Pin
Jun Du21-Jun-06 4:59
Jun Du21-Jun-06 4:59 
AnswerRe: Sort an std::vector?! Finished! Pin
bosfan21-Jun-06 20:58
bosfan21-Jun-06 20:58 
QuestionHuge size files IO- Performance issue? Pin
jayart21-Jun-06 3:53
jayart21-Jun-06 3:53 
AnswerRe: Huge size files IO- Performance issue? Pin
jayart21-Jun-06 3:56
jayart21-Jun-06 3:56 
QuestionRe: Huge size files IO- Performance issue? Pin
David Crow21-Jun-06 4:11
David Crow21-Jun-06 4:11 
AnswerRe: Huge size files IO- Performance issue? Pin
jayart21-Jun-06 6:02
jayart21-Jun-06 6:02 
GeneralRe: Huge size files IO- Performance issue? Pin
David Crow21-Jun-06 6:21
David Crow21-Jun-06 6:21 
GeneralRe: Huge size files IO- Performance issue? Pin
Zac Howland21-Jun-06 4:21
Zac Howland21-Jun-06 4:21 
AnswerRe: Huge size files IO- Performance issue? Pin
Ryan Binns21-Jun-06 4:29
Ryan Binns21-Jun-06 4:29 
AnswerRe: Huge size files IO- Performance issue? Pin
James R. Twine21-Jun-06 6:52
James R. Twine21-Jun-06 6:52 
Questionabout FARPROC* Pin
George_George21-Jun-06 3:05
George_George21-Jun-06 3:05 
AnswerRe: about FARPROC* Pin
zouchao111221-Jun-06 3:14
zouchao111221-Jun-06 3:14 
GeneralRe: about FARPROC* Pin
George_George21-Jun-06 17:20
George_George21-Jun-06 17:20 

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.