H
Haro Panosyan
#include <iostream>
#include <map>
#include <string>
using namespace std;
void InitMap( map<string, int>& Map)
{
Map["aa"] = 0;
Map["bb"] = 0;
}
int main() {
map<string, int> MyMap;
InitMap( MyMap);
MyMap["aa"] = 10;// Questione 1
MyMap["cc"] = 20;// Question 2
map<string, int>::const_iterator iter;
for (iter=MyMap.begin(); iter != MyMap.end(); iter++) {
cout << iter->first << " " << iter->second << endl;
}
return 0;
}
Question 1:
How do I create my own map, which would allow me to check during
MyMap["aa"] = 10;
that values for "aa" can be from 0 to 5, so the above assignment
would print error message.
Question 2:
How do I prevent my map to be only 2 elements, "aa" and "bb", so
creation of new element "cc" would not be allowed.
Thanks,
-haro
(I tried and failed, I googled and failed, so I came here.
Please excuse if this is very simple or discribed somewhere)
#include <map>
#include <string>
using namespace std;
void InitMap( map<string, int>& Map)
{
Map["aa"] = 0;
Map["bb"] = 0;
}
int main() {
map<string, int> MyMap;
InitMap( MyMap);
MyMap["aa"] = 10;// Questione 1
MyMap["cc"] = 20;// Question 2
map<string, int>::const_iterator iter;
for (iter=MyMap.begin(); iter != MyMap.end(); iter++) {
cout << iter->first << " " << iter->second << endl;
}
return 0;
}
Question 1:
How do I create my own map, which would allow me to check during
MyMap["aa"] = 10;
that values for "aa" can be from 0 to 5, so the above assignment
would print error message.
Question 2:
How do I prevent my map to be only 2 elements, "aa" and "bb", so
creation of new element "cc" would not be allowed.
Thanks,
-haro
(I tried and failed, I googled and failed, so I came here.
Please excuse if this is very simple or discribed somewhere)