473,395 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

what does find in the MAP do if no match is found for the key

I checked the microsoft MSDN and it says the following:

"find returns an iterator that addresses the location of an element
with a specified key, or the location succeeding the last element in
the map if no match is found for the key."
What does it mean by the location succeeding the last element.... how
do we know that the element not found in the MAP?

Dec 14 '06 #1
4 4300
OOPS... incomplete question..
If no match is found for the key, end( ) is returned

I can check if the returned item == m1.end( ) ). If so, item not
found.. otherwise use the returned value...

Is there any other way to find out that the item with the given key is
not found???

NewToCPP wrote:
I checked the microsoft MSDN and it says the following:

"find returns an iterator that addresses the location of an element
with a specified key, or the location succeeding the last element in
the map if no match is found for the key."
What does it mean by the location succeeding the last element.... how
do we know that the element not found in the MAP?
Dec 14 '06 #2

NewToCPP wrote:
I checked the microsoft MSDN and it says the following:

"find returns an iterator that addresses the location of an element
with a specified key, or the location succeeding the last element in
the map if no match is found for the key."
What does it mean by the location succeeding the last element.... how
do we know that the element not found in the MAP?
IIRC it returns a special iterator representing the end of the map(or
'one past the end' if you prefer)

Just compare the iterator returned:

if (my_map.find(id) == my_map.end()){
std::cout << id <<" not found\n";
}

regards
Andy Little

Dec 14 '06 #3

NewToCPP wrote:
OOPS... incomplete question..
If no match is found for the key, end( ) is returned

I can check if the returned item == m1.end( ) ). If so, item not
found.. otherwise use the returned value...

Is there any other way to find out that the item with the given key is
not found???
There are other ways, but they all end up at around about the same
place AFAICS... IOW the end(). std::map is meant to be a black box, but
it is usually implemented as a tree. The map sorts all the ids so that
it can find them fast, hence using find() is likely to be the fastest
and best method of finding things in the map..or not as the case may
be. The iterators are usually only useful to enumerate through the map
to see whats in there

hmm .. I love std::map :-)

regards
Andy Little

Dec 14 '06 #4

"NewToCPP" <he****@yahoo.comwrote in message
news:11**********************@79g2000cws.googlegro ups.com...

Please don't top-post. I've re-arranged your messages:
>
NewToCPP wrote:
>I checked the microsoft MSDN and it says the following:

"find returns an iterator that addresses the location of an element
with a specified key, or the location succeeding the last element in
the map if no match is found for the key."
What does it mean by the location succeeding the last element.... how
do we know that the element not found in the MAP?

OOPS... incomplete question..
If no match is found for the key, end( ) is returned

I can check if the returned item == m1.end( ) ). If so, item not
found.. otherwise use the returned value...

Is there any other way to find out that the item with the given key is
not found???

What's wrong with comparing with end()? That's the standard way to tell if
the find failed. Is that not working for you?

-Howard


Dec 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: timmy_dale12 | last post by:
Im implementing a calendar and cant figure out what this method does or how it works // datetime parsing and formatting routimes. modify them if you wish other datetime format function str2dt...
3
by: Gary McGill | last post by:
I have a C# solution with a dozen or so projects. There are references between the projects, and these were all added as "Project" references. Everything's been working fine for months, but...
1
by: Earl Teigrob | last post by:
I am parsing some HTML and need to match certain tag attributes to change from relative to absolute urls. The search string I am currently using is rex="src\\s*=\\s*\"(?<content>.+?)\""; that...
3
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
3
by: Alexandre | last post by:
Hi! I receive this error in my webapp: Ambiguous match found. At line: Line 1: <%@ page language="C#" masterpagefile="~/memberscontents/master_interna.master" autoeventwireup="true"...
0
by: Coach | last post by:
I have just migrated an application from VS2003 to VS2005 and now receive Ambigous Match Found error. I changed my Control Tag to represent 2005 and now I receive an error stating "another...
4
by: rn5a | last post by:
Consider the following code: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) Dim dInfo As DirectoryInfo dInfo = New DirectoryInfo(Server.MapPath("/Folder1"))...
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
2
by: aparna | last post by:
Hi, I have one project in dotnet 1.1and when I am trying to compile that project I am getting "Ambiguous match found" error in code behind file(.aspx.cs) but there is no such file in that...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.