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 7408
>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: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |