
Originally Posted by
VelvetTLeopard
I have a data that can only be one of two values. They are strings, say "black" and "White".
I was thinking of just using the string type, but then I thought it might be better to use a bool since the value can take only one of two values.
You can have both. This is just off the top of my head without putting a lot of thought into it:
Code:
#include <map>
#include <string>
#include <iostream>
typedef std::map<bool, std::string> BoolMap;
using namespace std;
int main()
{
BoolMap myMap;
// Initialize the map
myMap.insert(make_pair(true,"White"));
myMap.insert(make_pair(false,"Black"));
// Prove it works
cout << "The value of true is " << myMap[true] << "\n";
cout << "The value of false is " << myMap[false];
}
I'm sure others will add alternatives to the above.
Regards,
Paul McKenzie