Since you seem to want the simplest thing humanly possible, Iโm going to offer something incredibly simple that may or may not work based on your map contents. If your map data values โโare strings containing spaces, this will not work. If they are strings without spaces or numeric, you are configured.
This is not verified code, but it is close and simple, so you should be fine, even if it doesnโt quite compile. Just change KeyType and ValueType to int, string, float or whatever you are actually using in the file.
Configure the file as:
key value key2 value2 key3 value3 key4 value4
Read how:
KeyType key; ValueType value; std::map<KeyType, ValueType> myMap; while (infile >> key >> value) myMap[key] = value;
source share