for_each algorithm causing error

I cannot figure out why I get this error
Severity Code Description Project File Line Suppression State
Error C2664 'void (std::set<std::string,std::less<_Kty>,std::allocator<_Kty>>)': cannot convert argument 1 from 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>>' to 'std::set<std::string,std::less<_Kty>,std::allocator<_Kty>>' bskar2_InClass4 c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm 69

if I comment out the for_each(results.begin(), results.end(), doP);
on line 53 then the program executes. any tips on why this is happening?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <set>
#include <string>
#include <map>
#include <vector>
#include <iterator>
#include <algorithm>
#include <fstream>
using namespace std;

void doP(set<string>);
ostream& operator<< (ostream& out, set<string> &any);
bool compare(const pair<string, double> &, const pair<string, double> &);
set<string> criticsPick(map<string, double>);
int main()
{
	map<string, double> movieList;

	string fname = "Movies.txt";
	ifstream myfile;
	myfile.open(fname);

	if (myfile.is_open())
	{
		cout << "File Opened" << endl;
	}
	else
	{
		cout << "BAD : " + fname << endl;
		return -99;
	}
	string nameString = "";
	string scoreString = "";

	while (myfile)
	{
		getline(myfile, nameString);
		getline(myfile, scoreString);

		movieList[nameString] = atof(scoreString.c_str());
	}

	//map<string,double>::iterator it = movieList.begin();
	//while(it != movieList.end())
	//{
	// std::cout<<it->first<<" :: "<<it->second<<std::endl;
	// it++;
	//}

	set<string> results;
	results = criticsPick(movieList);

	for_each(results.begin(), results.end(), doP);
	system("pause");
}

void doP(set<string> i)
{
	cout << i << endl;
}
ostream& operator<< (ostream& out, set<string> &list)
{
	out << list;
	return out;
}
bool compare(const pair<string, double> &left, const pair<string, double> &right)
{
	return left.second > right.second;
}

set<string> criticsPick(map<string, double> list)
{
	set<string> setList;
	vector<pair<string, double>> vectorList;

	copy(list.begin(), list.end(), back_inserter(vectorList));
	sort(vectorList.begin(), vectorList.end(), compare);

	/*for (int i = 0; i < 10; i++)
	{
		cout << vectorList[i].first << vectorList[i].second << endl;
	}*/
	for (int i = 0; i < 10; i++)
	{
		setList.insert(vectorList[i].first);
	}
	/*for (set<string>::iterator iter = setList.begin(); iter != setList.end(); ++iter)
		cout << *iter << endl;*/
	return setList;
}
Change the parameter:doP(const string &i)
that worked, and makes complete sense. thanks
Topic archived. No new replies allowed.