I currently have this ode but I am not sure how to do the following question.
#include <list>
#include <string>
#include <iostream>
using namespace std;
int main(int argv, char* argc[])
{
int i;
list<int> l;
list<string> s;
int counter = 0;
do {
if (counter % 2 == 0) //counter is even
{
//read int and store in list<int>
int num;
cin >> num;
l.push_back(num);
if (num == 0)
break;
}
else // counter is odd
{
//read string and store in list<string>
string str;
cin >> str;
s.push_back(str);
}
counter++;
} while (true);
}
Copy your answer above. Adapt it so that each corresponding int and string are used as a key-value
pair for insertion into an STL map container.
I know I need to use map<key,val> but I am unsure how to do it.
std::map<int, std::string> theMap;
theMap[0] = "First string";
theMap[1000] = "string at index 1000";
std::cout << "The first string is " << theMap[0] << std::endl;