### 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.
 ``12345678910111213141516171819202122232425262728293031`` ``````#include #include #include #include #include using namespace std; int main() { list zahlen; list::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?

 Iam on the right way or not?
Not;)

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

 ``12345`` `````` map 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.