Map to String

So I am given the function where I am given a map that has a string key and a long value, and it is a pointer of m. I know how to print a map, but I am not sure on how to go about for taking the map and making it into a single string.
It should be printed as string:long, comma separting the elements with no comma at the end.

1
2
3
4
string map_to_string(map<string,long>  &m) {


}


Any help would be great, thank you!
it is a pointer of m

it is a reference to m actually
making it into a single string.

this suggests you want to convert the long into string as well, right? in that case ...
http://stackoverflow.com/questions/947621/how-do-i-convert-a-long-to-a-string-in-c
Thank you! That helped me and I was able to come up with this to get the correct output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
string map_to_string(map<string,long>  &m) {
string output = "";
string convrt = "";
string result = "";

	for (auto it = m.cbegin(); it != m.cend(); it++) {
	
		convrt = std::to_string(it->second);
		output += (it->first) + ":" + (convrt) + ", ";
	}
	
	result = output.substr(0, output.size() - 2 );
	
  return result;
}
Topic archived. No new replies allowed.