Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


6,849 questions

9,751 answers

573 users

How to make calculation with the value of each element in a map using C++

1 Answer

0 votes
#include <iostream>  
#include <map>
#include <string>
#include <algorithm>

using std::map;
using std::string;
using std::cout;
using std::endl;

void printMap(const map<string, double>& mp)
{
	for (auto element : mp) {
		cout << element.first << ": " << element.second << endl;
	}
	cout << endl;
}


int main()
{
	map<string, double> mp{ { "c++", 3.14 }, { "c", 5.18 } 	};

	for_each(mp.begin(), mp.end(), [](map<std::string, double>::value_type& element) {
		element.second *= 2;
	});

	printMap(mp);

	return 0;
}

/*
run:

c: 10.36
c++: 6.28

*/

 




answered Jan 10 by avibootz
...