Click here to Skip to main content
15,892,005 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to capture ctrl+down arrow key. Pin
baerten22-Oct-07 1:13
baerten22-Oct-07 1:13 
GeneralThanks.[SOLVED] Pin
chandu00422-Oct-07 1:31
chandu00422-Oct-07 1:31 
AnswerRe: how to capture ctrl+down arrow key. Pin
jhwurmbach22-Oct-07 1:18
jhwurmbach22-Oct-07 1:18 
GeneralRe: how to capture ctrl+down arrow key. Pin
chandu00422-Oct-07 1:35
chandu00422-Oct-07 1:35 
QuestionHelp for stdext::hash_map in VS2005! Pin
bosfan21-Oct-07 23:16
bosfan21-Oct-07 23:16 
AnswerRe: Help for stdext::hash_map in VS2005! [modified] Pin
jhwurmbach22-Oct-07 1:21
jhwurmbach22-Oct-07 1:21 
GeneralRe: Help for stdext::hash_map in VS2005! Pin
bosfan22-Oct-07 22:45
bosfan22-Oct-07 22:45 
GeneralRe: Help for stdext::hash_map in VS2005! Pin
jhwurmbach23-Oct-07 0:02
jhwurmbach23-Oct-07 0:02 
Your code does not even compile!
Anyway, are you positivly sure you want a hash_map here?
You do not have a good hash at hand, it seems. A normal map would be smarter, I think.

Anyway,
typedefs can help you sort the myriads of < and >.
str_compare should do what exactly? Define a strict ordering between the items given. Look how less<> works and define your comparer accordingly.

Here, I have used the standard less comparer.

And you are right, it doesn't work when mixing CString and LPCTSTR in insert and find. My version works if LPCTSTR or CString are used consistently.
#include "stdafx.h"
#include <hash_map>
#include "iostream"
#include "windows.h"
#include "atlstr.h"


class CMyClass
{
public:
	// some CStrings, integers etc!
	// for example:
	CString csName;
	CString csVName;
	int iAge;
};

int _tmain(int argc, _TCHAR* argv[])
{
	// items for map:
	CMyClass instance1;
	instance1.csVName = _T("John-Boy");
	instance1.csName = _T("Walton");
	instance1.iAge = 20;
	CMyClass instance2;
	instance2.csVName = _T("Jim-Bob");
	instance2.csName = _T("Walton");
	instance2.iAge = 16;

	// the hash_map:
	typedef stdext::hash_map<LPCTSTR, CMyClass, stdext::hash_compare<LPCTSTR, std::less<LPCTSTR> > > MyHashMapT;
	typedef MyHashMapT::iterator MyHashMapIt;
	MyHashMapT myhashmap;

	// add items to map:
	std::pair<MyHashMapIt, bool> result = myhashmap.insert( MyHashMapT::value_type( _T("John-Boy")/*instance1.csVName*/, instance1));
	result = myhashmap.insert(  MyHashMapT::value_type( _T("Jim-Bob")/*instance2.csVName*/, instance2));
	
	// iterator to find items in stdext::hash_map:
	MyHashMapIt testiterator = myhashmap.find( _T("John-Boy")/*instance1.csVName*/);
	if( myhashmap.end() != testiterator)
		std::wcout << _T("Item found") << std::endl;
	else
		std::wcout << _T("Item not found") << std::endl;

	return system("pause");
}



Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
Douglas Adams, "Dirk Gently's Holistic Detective Agency"

GeneralRe: Help for stdext::hash_map in VS2005! Pin
bosfan23-Oct-07 0:54
bosfan23-Oct-07 0:54 
GeneralRe: Help for stdext::hash_map in VS2005! Pin
jhwurmbach23-Oct-07 1:01
jhwurmbach23-Oct-07 1:01 
GeneralRe: Help for stdext::hash_map in VS2005! Pin
bosfan25-Oct-07 4:34
bosfan25-Oct-07 4:34 
GeneralRe: Help for stdext::hash_map in VS2005! Pin
jhwurmbach25-Oct-07 4:41
jhwurmbach25-Oct-07 4:41 
QuestionEmbedding Copy Exe in Application Exe? Pin
Ash2021-Oct-07 23:03
Ash2021-Oct-07 23:03 
AnswerRe: Embedding Copy Exe in Application Exe? Pin
Renjith Ramachandran22-Oct-07 0:41
Renjith Ramachandran22-Oct-07 0:41 
AnswerRe: Embedding Copy Exe in Application Exe? Pin
Nibu babu thomas22-Oct-07 0:42
Nibu babu thomas22-Oct-07 0:42 
AnswerRe: Embedding Copy Exe in Application Exe? Pin
JudyL_MD22-Oct-07 3:03
JudyL_MD22-Oct-07 3:03 
Questionassert Pin
George_George21-Oct-07 22:35
George_George21-Oct-07 22:35 
AnswerRe: assert Pin
Matthew Faithfull21-Oct-07 23:08
Matthew Faithfull21-Oct-07 23:08 
GeneralRe: assert Pin
George_George22-Oct-07 0:10
George_George22-Oct-07 0:10 
GeneralRe: assert Pin
Matthew Faithfull22-Oct-07 0:46
Matthew Faithfull22-Oct-07 0:46 
GeneralRe: assert Pin
George_George22-Oct-07 1:52
George_George22-Oct-07 1:52 
GeneralRe: assert Pin
Stephen Hewitt22-Oct-07 15:36
Stephen Hewitt22-Oct-07 15:36 
AnswerRe: assert Pin
David Crow22-Oct-07 3:45
David Crow22-Oct-07 3:45 
GeneralRe: assert Pin
George_George22-Oct-07 19:26
George_George22-Oct-07 19:26 
GeneralRe: assert Pin
David Crow23-Oct-07 2:55
David Crow23-Oct-07 2:55 

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.