| | | | | |

Using AssociativeArray

Using operator[] to write to and read from table

fsu::AssociativeArray<fsu::String,int> aa;
fsu::String                       aKey;
int                               someData;
std::ifstream                     ifs;
ifs.open(someFile);
while (ifs >> aKey >> someData)
{
  aa[aKey] = someData;
//^^^^^^^^^^^^^^^^^^^ inserts (aKey,someData) into table - "Put" behavior
}
ifs.close();
// now entire file is loaded into symbol table
...
// typical query loop:
while(1)
{
  std::cout << "Enter key: ";
  std::cin >> aKey;
  std::cout << "data from key " << aKey << " = "
            << aa[aKey] << '\n'; 
//             ^^^^^^^^ returns data stored with aKey - "Get" behavior 
}

| | Top of Page | 10. Introduction to Maps - 7 of 11