Click here to Skip to main content
15,173,985 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Insert into map Pin
George_George27-Aug-08 20:35
MemberGeorge_George27-Aug-08 20:35 
GeneralRe: Insert into map Pin
Nibu babu thomas27-Aug-08 20:38
MemberNibu babu thomas27-Aug-08 20:38 
GeneralRe: Insert into map Pin
George_George27-Aug-08 20:42
MemberGeorge_George27-Aug-08 20:42 
GeneralRe: Insert into map Pin
Nibu babu thomas27-Aug-08 20:49
MemberNibu babu thomas27-Aug-08 20:49 
GeneralRe: Insert into map Pin
George_George27-Aug-08 20:57
MemberGeorge_George27-Aug-08 20:57 
GeneralRe: Insert into map Pin
Nibu babu thomas27-Aug-08 21:21
MemberNibu babu thomas27-Aug-08 21:21 
GeneralRe: Insert into map Pin
George_George27-Aug-08 21:48
MemberGeorge_George27-Aug-08 21:48 
AnswerRe: Insert into map Pin
Jijo.Raj27-Aug-08 19:58
MemberJijo.Raj27-Aug-08 19:58 
George_George wrote:
When using mapvariable[somekey] = somevalue to insert into a map variable, how to check whether there is conflicting key value in the map in an elegant way?


You can use map::find() to check whether the key is already present in map. Well, the [] operator will overwrite the existing entry if the key already exists.

OT: Be a little careful while using [] operator with map, especially while reading from map. For instance, if you try to get a key-value which is not in map, it create a new entry and return the default value. For instance,

// An empty map.
map<cstring,cstring> TempMap;

// If you lookup a for a key which is not present,
// it will create empty entry and return. It won't
// throw any error.
CString LookupKey = _T("key"); // Key which is not present.
CString Value = TempMap[LookupKey];


Regards,
Jijo.

_____________________________________________________

http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

GeneralRe: Insert into map Pin
George_George27-Aug-08 20:39
MemberGeorge_George27-Aug-08 20:39 
GeneralRe: Insert into map Pin
Jijo.Raj27-Aug-08 21:05
MemberJijo.Raj27-Aug-08 21:05 
GeneralRe: Insert into map Pin
George_George27-Aug-08 21:49
MemberGeorge_George27-Aug-08 21:49 
Questionmulity line edit control Pin
ani_ikram27-Aug-08 18:53
Memberani_ikram27-Aug-08 18:53 
AnswerRe: mulity line edit control Pin
Naveen27-Aug-08 19:20
MemberNaveen27-Aug-08 19:20 
GeneralRe: mulity line edit control Pin
ani_ikram27-Aug-08 20:01
Memberani_ikram27-Aug-08 20:01 
QuestionRe: mulity line edit control Pin
David Crow28-Aug-08 4:59
MemberDavid Crow28-Aug-08 4:59 
QuestionCArray::RemoveAt() causes Unhandled exception Pin
rp_suman27-Aug-08 17:13
Memberrp_suman27-Aug-08 17:13 
QuestionRe: CArray::RemoveAt() causes Unhandled exception Pin
Mark Salsbery28-Aug-08 7:16
MemberMark Salsbery28-Aug-08 7:16 
QuestionChanging the filenames in the Common File Dialog Pin
Tony Rowe27-Aug-08 15:51
MemberTony Rowe27-Aug-08 15:51 
Questionstl::list --- Issue using lists.. Pin
FrankMookie27-Aug-08 14:22
MemberFrankMookie27-Aug-08 14:22 
QuestionRe: stl::list --- Issue using lists.. Pin
Maximilien27-Aug-08 14:32
MemberMaximilien27-Aug-08 14:32 
AnswerRe: stl::list --- Issue using lists.. Pin
FrankMookie27-Aug-08 14:42
MemberFrankMookie27-Aug-08 14:42 
GeneralRe: stl::list --- Issue using lists.. Pin
David Crow28-Aug-08 5:02
MemberDavid Crow28-Aug-08 5:02 
GeneralRe: stl::list --- Issue using lists.. Pin
FrankMookie28-Aug-08 5:26
MemberFrankMookie28-Aug-08 5:26 
GeneralRe: stl::list --- Issue using lists.. Pin
David Crow28-Aug-08 5:36
MemberDavid Crow28-Aug-08 5:36 
GeneralRe: stl::list --- Issue using lists.. Pin
FrankMookie28-Aug-08 5:40
MemberFrankMookie28-Aug-08 5:40 

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.