Clear a MAP 
Author Message
 Clear a MAP

How do you clear or empty a map?   I try searching for "Clear Map" and I
don't get anything about C++.

I have this in my Init.h
 typedef std::map< long, std::string, std::less< long > > HEADERS;
 HEADERS m_mapHeaders;

I have a function that does this..
 m_mapHeaders[m_iHeaderCount] = strNewVal;
 m_iHeaderCount += 1;

I have a function call ResetHeader().  This is to clear the map.  Now I know
I can just reset the  m_iHeaderCount = 0 and everything will work just as I
want it to, but the map it self still has all the data in it, even if it's
not used because other code is looking at the m_iHeaderCount..  I want to
empty this map, just to be clean.  How can I do this without looping through
and clearing each element?  Or is this the only way to do it?



Thu, 23 Sep 2004 04:27:23 GMT  
 Clear a MAP

Quote:

> How do you clear or empty a map?   I try searching for "Clear Map" and I
> don't get anything about C++.

> I have this in my Init.h
>  typedef std::map< long, std::string, std::less< long > > HEADERS;
>  HEADERS m_mapHeaders;

> I have a function that does this..
>  m_mapHeaders[m_iHeaderCount] = strNewVal;
>  m_iHeaderCount += 1;

> I have a function call ResetHeader().  This is to clear the map.  Now I know
> I can just reset the  m_iHeaderCount = 0 and everything will work just as I
> want it to, but the map it self still has all the data in it, even if it's
> not used because other code is looking at the m_iHeaderCount..  I want to
> empty this map, just to be clean.  How can I do this without looping through
> and clearing each element?  Or is this the only way to do it?

m_mapHeaders.clear();


Fri, 24 Sep 2004 11:57:51 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. clearing the map

2. map pecularity, char[] not destroyed on clear/erase?

3. Chicago Map's Precision Mapping OCX

4. Memory-mapped files - pros and cons of mapping view on whole file

5. stl::map - can't map int to char *

6. Accessing map elements in vector of maps

7. map::mapped_type vs. map::referent_type

8. map::erase( map::end() ) is it harmless?

9. Problem with using map .erase inside a map loop

10. inserting into map of maps

11. Memery mapped map

12. MFC map or stl map

 

 
Powered by phpBB® Forum Software