Converting a list to a map??

Hello, currently Iam have to solve some exercises in C++ .

First is, I have to fill a list with 100 random numbers.
Then I have to delete all numbers who are even.
No Problem here is my code.
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
#include <vector > 
#include <list > 
#include <iostream > 
#include <iterator > 
#include <algorithm > 
using namespace std;


int main()
{

	list<int> zahlen;		   
    list<int>::iterator lIter; 

    srand(0); //Bestimmung der Zufallszahl
    for(int i=0; i<100; i++) 
    {
        zahlen.push_back( rand() % 99 + 1 );  
    }
    // Durchlaufen und anzeigen
    for(lIter=zahlen.begin(); lIter!=zahlen.end(); ++lIter)
    {
        if (*lIter%2!=0)
		{
		cout << *lIter  << " " ;
		}
    }
	
	getchar();
	return 0;
}


Then I need to get the frequency of all numbers, the excersise says I have to use the "std::map" so my idea would be.
Convert the list to a map and then just use the map::count to get the frequency of all numbers!

Iam on the right way or not?
If yes, how I can convert a list to a map?
If not, what I should do?

Thanks for answering!
Iam on the right way or not?
Not;)

If not, what I should do?
map is somehow simplier than a list:

1
2
3
4
5
    map<int, int> m;
    for(int i=0; i<100; i++) 
    {
        ++(m[rand() % 99 + 1]);
    }


Now the map contains the frequency of each number. You have to iterate through the map.
Hint: the iterator is a pair
Topic archived. No new replies allowed.