I want to give an array the values from the specific multimap's key's values. -
multimap<string,int> mymultimap;
-
multimap<string,int>::iterator it;
-
pair<multimap<string,int>::iterator,multimap<string,int>::iterator> ret;
-
-
mymultimap.insert (pair<string,int>("test",10));
-
mymultimap.insert (pair<string,int>("test",20));
-
mymultimap.insert (pair<string,int>("ab",100));
-
mymultimap.insert (pair<string,int>("ab",200));
-
-
int arr[2];
-
-
ret = mymultimap.equal_range("test");
-
for (it=ret.first; it!=ret.second; ++it){
-
arr[it] = (*it).second; //arr[it] results in an error.
-
}
-
With this code I want the array 'arr' to have the same values as 'mymultimap's "test" values, which is: 10 and 20. But as the iterator 'it' isn't an int/char etc. it can't be assorted with the array 'arr'
1 2702 Laharl 849
Recognized Expert Contributor
You can use a while loop and a count variable. -
int count;
-
while (it != ret.end()){
-
arr[count] = (*i).second;
-
count++;
-
}
-
You can use a for loop, but it feels a little redundant in this case.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Tanguy Fautré |
last post by:
Hello,
does std::multimap make any guarantee about the insertion order?
for example:
int main()
{
std::multimap<int, int> Map;
|
by: Dennis Jones |
last post by:
Hi,
Is there a way to iterate through a multimap in such a way as to encounter
only the unique keys? In other words, since a multimap allows duplicate
keys, I would like to iterate through the entire multimap, and if a
particular key has duplicates, only see one of them. I don't think I care
about which of the duplicate entries I see,...
|
by: Przemek |
last post by:
All,
what is the efficient way to find all distinct keys in a multimap.
I use the code
template<class T1, class T2>
set<T1> GetDistinctKeys(multimap<T1, T2> nMap)
{
T1 temp;
multimap<T1, T2>::iterator i_ptr;
|
by: Nick Keighley |
last post by:
Hi,
I've checked out various documentation for multimap but can't
find anywhere it explicitly stated that insert() invalidates multimap
iterators.
consider this pseudo code:-
int DataItem::genDerived ()
{
|
by: giuseppe.cannella |
last post by:
i must create a muiltimap with 2 string , 1 int and 1 iterator to
multimap itself
how could define the typedef?
thank
| |
by: sks |
last post by:
I have a question regarding std::multimap/iterators.
At the SGI website, it says "Erasing an element from a multimap also does
not invalidate any iterators, except, of course, for iterators that actually
point to the element that is being erased."
I design/implemented a observer pattern that is priority based. It so
happened that...
|
by: ambarish.mitra |
last post by:
Hi all,
I have a multimap, where key is an int and the value is a class. I can
insert into the multimap, but finding it difficult to retrieve the
value when keys match. I can do this with primitive types (int/char
etc).
Example:
class A {
|
by: puzzlecracker |
last post by:
I am using while loop for that but I am sure you can do it quicker and
more syntactically clear with copy function.
Here is what I do and would like to if someone has a cleaner solution:
vector<stringvec;
multimap<stirng, intmyMap
// populate myMap
|
by: Moschops |
last post by:
In moving some code from VS6 to VS2008 (bear with me, this is not a VS
question, I'm just setting context), we find new crashes that weren't there
before and we think they're related to trying an operation on a multimap
that is empty - for example,
std::multimap<double, aStructWeHaveDefined>::iterator low;
low = c.begin() ; // c is empty...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |