map problem 
Author Message
 map problem

Hi,

I have a couple of maps:

map1<BSTR, DATE>
map2<BSTR, DATE>

in which there are a load of filenames and their dates. I want to see if
files in map1 are in map2, so I tried:

map<BSTR, DATE>::iterator iter = map1.begin();
while(iter != map1.end())
{
    if(map2.find(iter->first) != map2.end())
           match = true;
    iter++;

Quote:
}

But I cannot get this to find a match (There should be matches - I have
printed them out!).
Does the map.find() function just compare the BSTR pointers or the actual
strings?

I got around the problem by iterating the whole of map2 in place of the
find() call and doing a strcmp on each pair of BSTR's, but just wondered if
there was a better way.

cheers

Dave



Tue, 30 Sep 2003 07:22:08 GMT  
 map problem
BSTR is typedef'ed to be wchar_t*. The map uses operator< to order keys and
to decide when two keys are equal. Lacking mindreading abilities, it doesn't
realise that you want bstr1 < bstr2 to mean lstrcmpW(bstr1, bstr2) < 0

Use wrapper classes as keys. Both CComBSTR and _bstr_t provide suitable
operator<
--
With best wishes,
    Igor Tandetnik


Quote:
> Hi,

> I have a couple of maps:

> map1<BSTR, DATE>
> map2<BSTR, DATE>

> in which there are a load of filenames and their dates. I want to see if
> files in map1 are in map2, so I tried:

> map<BSTR, DATE>::iterator iter = map1.begin();
> while(iter != map1.end())
> {
>     if(map2.find(iter->first) != map2.end())
>            match = true;
>     iter++;
> }

> But I cannot get this to find a match (There should be matches - I have
> printed them out!).
> Does the map.find() function just compare the BSTR pointers or the actual
> strings?

> I got around the problem by iterating the whole of map2 in place of the
> find() call and doing a strcmp on each pair of BSTR's, but just wondered
if
> there was a better way.

> cheers

> Dave



Tue, 30 Sep 2003 07:56:59 GMT  
 map problem
Thanks for that, I will give it a go ( think I tried CComBSTR first but the
compiler complained about something - cant remember what - so I went to
BSTR)

Dave.

Quote:
> BSTR is typedef'ed to be wchar_t*. The map uses operator< to order keys
and
> to decide when two keys are equal. Lacking mindreading abilities, it
doesn't
> realise that you want bstr1 < bstr2 to mean lstrcmpW(bstr1, bstr2) < 0

> Use wrapper classes as keys. Both CComBSTR and _bstr_t provide suitable
> operator<
> --
> With best wishes,
>     Igor Tandetnik



> > Hi,

> > I have a couple of maps:

> > map1<BSTR, DATE>
> > map2<BSTR, DATE>

> > in which there are a load of filenames and their dates. I want to see if
> > files in map1 are in map2, so I tried:

> > map<BSTR, DATE>::iterator iter = map1.begin();
> > while(iter != map1.end())
> > {
> >     if(map2.find(iter->first) != map2.end())
> >            match = true;
> >     iter++;
> > }

> > But I cannot get this to find a match (There should be matches - I have
> > printed them out!).
> > Does the map.find() function just compare the BSTR pointers or the
actual
> > strings?

> > I got around the problem by iterating the whole of map2 in place of the
> > find() call and doing a strcmp on each pair of BSTR's, but just wondered
> if
> > there was a better way.

> > cheers

> > Dave



Thu, 02 Oct 2003 02:48:30 GMT  
 map problem

Quote:
> I tried CComBSTR first but the
> compiler complained about something - cant remember what - so I went to
> BSTR)

Wrap it w/ CAdapt<> e.g.:

    map< CAdapt<CComBSTR>, DATE > ...

Cheers,
Vadim.

Quote:

> Dave.

> > BSTR is typedef'ed to be wchar_t*. The map uses operator< to order keys
> and
> > to decide when two keys are equal. Lacking mindreading abilities, it
> doesn't
> > realise that you want bstr1 < bstr2 to mean lstrcmpW(bstr1, bstr2) < 0

> > Use wrapper classes as keys. Both CComBSTR and _bstr_t provide suitable
> > operator<
> > --
> > With best wishes,
> >     Igor Tandetnik



> > > Hi,

> > > I have a couple of maps:

> > > map1<BSTR, DATE>
> > > map2<BSTR, DATE>

> > > in which there are a load of filenames and their dates. I want to see
if
> > > files in map1 are in map2, so I tried:

> > > map<BSTR, DATE>::iterator iter = map1.begin();
> > > while(iter != map1.end())
> > > {
> > >     if(map2.find(iter->first) != map2.end())
> > >            match = true;
> > >     iter++;
> > > }

> > > But I cannot get this to find a match (There should be matches - I
have
> > > printed them out!).
> > > Does the map.find() function just compare the BSTR pointers or the
> actual
> > > strings?

> > > I got around the problem by iterating the whole of map2 in place of
the
> > > find() call and doing a strcmp on each pair of BSTR's, but just
wondered
> > if
> > > there was a better way.

> > > cheers

> > > Dave



Thu, 02 Oct 2003 03:33:01 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Message map problem

2. Screen Mapping Problem

3. attributes -> interface map problems

4. STL map problem

5. Borland c++ v4.02 DOS Powerpack Key map problem

6. Template map problem

7. VC++5.0 Map problem

8. Unregular message mapping problem

9. MFC Message mapping problem

10. message mapping problem

11. Client Area Mapping Problem

12. File Mapping Problems

 

 
Powered by phpBB® Forum Software