Hi everybody,
This should be trivial, but I just can't see it.
The following statement in a method doesn't work for me:
(there's only one entry in myMap)
map<const char*, int>::const_iterator it = myMap.find(key);
where key is a const char* passed by the class method.
However, if I do:
map<const char*, int>::const_iterator it = registry.begin();
Then the iterator points to the right value, and (*it).first displays the
right key.
I have checked the key value being passed to find() and is correct, so that
shouldn't be a problem...
Any hints?
Cheers
--
================================================== ======================
Manuel Diaz-Gomez | ATLAS Bldg. 32/SB-008 tel. +41 22 76 76304
CERN EP Division
CH-1211 Geneva 23
SWITZERLAND
================================================== ====================== 3 7427
>map<const char*, int>::const_iterator it = myMap.find(key);
Your map compares C-string addresses, not C-string contents
Manuel Maria Diaz Gomez wrote: Hi everybody,
This should be trivial, but I just can't see it. The following statement in a method doesn't work for me: (there's only one entry in myMap)
map<const char*, int>::const_iterator it = myMap.find(key);
where key is a const char* passed by the class method.
However, if I do:
map<const char*, int>::const_iterator it = registry.begin();
Then the iterator points to the right value, and (*it).first displays the right key. I have checked the key value being passed to find() and is correct, so that shouldn't be a problem...
Any hints?
What Walter said.
Use std::string instead of const char* as the key type.
That solved the problem!!
Thanks!
Manuel
"Manuel Maria Diaz Gomez" <Ma*********************@cern.ch> wrote in message
news:c6**********@sunnews.cern.ch... Hi everybody,
This should be trivial, but I just can't see it. The following statement in a method doesn't work for me: (there's only one entry in myMap)
map<const char*, int>::const_iterator it = myMap.find(key);
where key is a const char* passed by the class method.
However, if I do:
map<const char*, int>::const_iterator it = registry.begin();
Then the iterator points to the right value, and (*it).first displays the right key. I have checked the key value being passed to find() and is correct, so
that shouldn't be a problem...
Any hints?
Cheers -- ================================================== ====================== Manuel Diaz-Gomez | ATLAS Bldg. 32/SB-008 tel. +41 22 76 76304 CERN EP Division CH-1211 Geneva 23 SWITZERLAND ================================================== ======================
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Duane Hebert |
last post by:
2 questions:
Given a map defined as
std::map<int,string> stringmap;
//How do you access the data_type (string) via an iterator?
std::string spoo("doh");
|
by: jmoy |
last post by:
I am a C programmer graduating to C++. As an exercise I wrote a
program to count the number of times that different words occur in a
text file. Though a hash table might have been a better choice,...
|
by: Grey Plastic |
last post by:
I do not understand why this code fails to compile (under gcc):
#include <map>
using namespace std;
class Foo {
map<Foo*,int> myMap;
public:
int lookup(const Foo& f) const { myMap.find(&f);...
|
by: Flzw |
last post by:
Well I have a map like this :
std::map <string, CObject> ObjectList;
I have a function like this :
CObject* NewObject( char* Name, CArg* Arg)
{
std::string key = Name;
ObjectList =...
|
by: jstanforth |
last post by:
This is probably a very obvious question, but I'm not clear on what
operators need to be implemented for std::map.find() to work. For
example, I have a class MyString that wraps std::string, and...
| |
by: kamaraj80 |
last post by:
Hi
I am using the std:: map as following.
typedef struct _SeatRowCols
{
long nSeatRow;
unsigned char ucSeatLetter;
}SeatRowCols;
typedef struct _NetData
|
by: mergaite_lietuvaite |
last post by:
Hi,
I try to use map. My code is very easy, but there are some errors....
(by compiling). Plaese, could you say, what I do wrong..
struct less_array
{
bool operator()(const FArray p1, const...
|
by: DevNull |
last post by:
Hi there everyone,
I'm creating a very simple immediate mode command interpreter.
The final purpose is to provide a pluggable control and command
console for a MUD server I have written.
The...
|
by: Matthias Pfeifer |
last post by:
Hi there,
a std::map is build from std::pair elements where for a pair p p.first
is called the key and p.second the value. Is there a way to keep the map
sorted by the values? Ie is there a...
|
by: mveygman |
last post by:
Hi,
I am writing code that is using std::map and having a bit of an issue
with its performance.
It appears that the std::map is significantly slower searching for an
element then a sequential...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
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...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |