Hi all,
I'm starting to fool around with STL and in particular std::map.
How do I iterate through one map and insert every pair in another map?
I have the following so far:
map<double, doublefset1;
map<double, doublefset3;
fset1.insert(pa ir<double, double>(1.0,0.4 ));
// etc etc more values etc etc
ifs1 = fset1.begin();
while(ifs1 != fset1.end())
{
// how to insert is the q!
}
Thanks for your time!
Evyn 4 6251
Evyn wrote:
Hi all,
I'm starting to fool around with STL and in particular std::map.
How do I iterate through one map and insert every pair in another map?
By using std::copy.
I have the following so far:
map<double, doublefset1;
map<double, doublefset3;
fset1.insert(pa ir<double, double>(1.0,0.4 ));
fset1.insert(ma ke_pair(1.0,0.4 ));
// etc etc more values etc etc
ifs1 = fset1.begin();
while(ifs1 != fset1.end())
{
// how to insert is the q!
fset3.insert(*i fs1);
++ifs1;
}
Evyn wrote:
Hi all,
I'm starting to fool around with STL and in particular std::map.
How do I iterate through one map and insert every pair in another map?
I have the following so far:
map<double, doublefset1;
map<double, doublefset3;
fset1.insert(pa ir<double, double>(1.0,0.4 ));
// etc etc more values etc etc
ifs1 = fset1.begin();
while(ifs1 != fset1.end())
{
// how to insert is the q!
}
std::copy( fset1.begin(), fset1.end(),
std::inserter( fset2, fset2.begin() ) );
E.g.:
#include <map>
#include <algorithm>
#include <iterator>
#include <iostream>
int main ( void ) {
std::map< int, int a;
std::map< int, int b;
b[2] = 1;
b[4] = 2;
a[3] = 0;
a[5] = 2;
std::copy( a.begin(), a.end(),
std::inserter( b, b.begin() ) );
for ( std::map< int, int >::const_iterat or iter = b.begin();
iter != b.end(); ++iter ) {
std::cout << iter->first
<< " --"
<< iter->second
<< "\n";
}
}
Best
Kai-Uwe Bux
Thanks for the help!
On Jan 19, 2:37 pm, Kai-Uwe Bux <jkherci...@gmx .netwrote:
Evyn wrote:
Hi all,
I'm starting to fool around with STL and in particular std::map.
How do I iterate through one map and insert every pair in another map?
I have the following so far:
map<double, doublefset1;
map<double, doublefset3;
fset1.insert(pa ir<double, double>(1.0,0.4 ));
// etc etc more values etc etc
ifs1 = fset1.begin();
while(ifs1 != fset1.end())
{
// how to insert is the q!
}std::copy( fset1.begin(), fset1.end(),
std::inserter( fset2, fset2.begin() ) );
E.g.:
#include <map>
#include <algorithm>
#include <iterator>
#include <iostream>
int main ( void ) {
std::map< int, int a;
std::map< int, int b;
b[2] = 1;
b[4] = 2;
a[3] = 0;
a[5] = 2;
std::copy( a.begin(), a.end(),
std::inserter( b, b.begin() ) );
for ( std::map< int, int >::const_iterat or iter = b.begin();
iter != b.end(); ++iter ) {
std::cout << iter->first
<< " --"
<< iter->second
<< "\n";
}
}Best
Kai-Uwe Bux- Hide quoted text -- Show quoted text -
Evyn wrote:
Hi all,
I'm starting to fool around with STL and in particular std::map.
How do I iterate through one map and insert every pair in another map?
I have the following so far:
map<double, doublefset1;
map<double, doublefset3;
fset1.insert(fs et3.begin(), fset3.end()); 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, I
chose to use std::map. However, the program runs at less than half the
speed of an equivalent program that uses ordinary handcoded binary
trees. The result is not changed very much if I replace std::string as
the key with a simple string class...
|
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 = CObject( Name, Arg);
|
by: Erik Arner |
last post by:
Hi,
let's say I have a std::map<std::string,int> and I want to search the map
for all keys that start with "foo". The regexp equivalent is to search for
"foo*", or perhaps "^foo*".
At present I do this quick'n'dirty by appending a tilde (~) to the query
term, since I know it's last in the ascii table and my keys don't include
any special characters. So to find everything that starts with "foo" I
search the map from...
|
by: Erik Wikström |
last post by:
First of all, forgive me if this is the wrong place to ask this question,
if it's a stupid question (it's my second week with C++), or if this is
answered some place else (I've searched but not found anything).
Here's the problem, I have two sets of files, the name of a file contains a
number which is unique for each set but it's possible (even probable) that
two files in different sets have the same numbers. I want to store these...
| |
by: Dan Trowbridge |
last post by:
Hi everyone,
In my attempt to port code from VS 6.0 to VS.NET I had some code break along
the way, mostly due to not adhereing closely to the C++ standard. This may
be another instance but I can't think of a good fix, or even why it broke.
The problem
In one of my CFormView derived classes I have a member variable of the
type...
|
by: Jim Langston |
last post by:
Expected output of program:
Key is: 0 String is: Hello
Key is: 1 String is: Goodbye
Key is: 2 String is: The end
Actual output:
Key is: 0 String is: The End
Key is: 1 String is:
Key is: 2 String is:
|
by: simon.elbaz |
last post by:
Hi,
i use the following map:
std::map<Key, std::vector< std::string >, KeyCmp mSQLElem;
The following code does not insert the newly created pair:
std::vector<std::stringvcTemp;
vcTemp.push_back("test string");
mSQLBody.insert(std::make_pair(Key(stKey, mSQLBody.size(),
b_is_key_unique), std::vector< std::string >(vcTemp)));
|
by: guido |
last post by:
Hi,
I'm looking for a container class that can map whole ranges of keys to
objects - something like std::map, but not only for individual values for
the key, but for whole ranges.
Example:
I want to be able to tell the container to return object a for every given
key between 0 and 10, object c for every key between 11 and 500000 and
object c for every key between 500001 and 599999, without having to
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |