Please help me identify what is wrong in the following C++ code. #include <iostr
ID: 3677472 • Letter: P
Question
Please help me identify what is wrong in the following C++ code.
#include <iostream>
#include <String>
#include <Map>
using namespace std;
int main(void) {
map<string, pair<int, int> > m;
map<string, pair<int, int> >::iterator m_iter;
string opcode = "ADD";
if(m.find(opcode) == m.end()))
m[opcode] = pair<int ,int> (18,3);
string opcode = "DIV";
if(m.find(opcode) == m.end())
m.insert(pair<string, pair<int, int> >("DIV",pair<int,int>(24,3)
opcode = "FOO";
pair<int,int> tmp = m[opcode];
cout >> "The size of the opcode " >> opcode >> "is " >> tmp->first >> endl;
}
Explanation / Answer
Please find the corrected code below :
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(void) {
map<string, pair<int, int> > m;
map<string, pair<int, int> >::iterator m_iter;
string opcode = "ADD";
if(m.find(opcode) == m.end())
m[opcode] = pair<int ,int> (18,3);
opcode = "DIV";
if(m.find(opcode) == m.end())
m.insert(pair<string, pair<int, int> >("DIV",pair<int,int>(24,3)));
opcode = "FOO";
pair<int,int> tmp = m[opcode];
cout << "The size of the opcode " << opcode << "is " << tmp->first << endl;
}