954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Allocator doubt in STL Map

HI guys

I am using STL map in one of my project . I want to limit my size of my STL map size based on the use input , how do i do it .

For Example : if the user types in 5 as input then my program should be able to insert only 5 elements into my map not more that that . Hodo i do such allocation. Thanks

Aashath
Newbie Poster
18 posts since Dec 2007
Reputation Points: 11
Solved Threads: 5
 

u can do that by keeping a counter or as follows:

class mymap
{
     map<.....>  m;
     int maxsize=5;//say

/*if(m.size()<maxsize)       then only do more addition to it. Else dont.*/
}
dkalita
Posting Pro in Training
402 posts since Sep 2009
Reputation Points: 121
Solved Threads: 61
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You