Question: I have a map and a vector as follows - map val; vector que = {name2, name1, value1}; val[name2] = Name1; val[value1] = HelloWorld; What

I have a map and a vector as follows -

map val;

vector que = {"name2", "name1", "value1"};

val["name2"] = "Name1";

val["value1"] = "HelloWorld"; What i want is for each element in que, I want if the element matches the attribute in map 'val'..I want to print the value of 'val'... EXAMPLE - "name2" in que vector matches the attribute "name2" in val..so if it matches I want to print the value, here the value supposed to print is "Name1"..but if it doesn't match..i want to print "Not Found!" Here's the code for the same -

int main ()

{

map val;

vector que = {"name2", "name1", "value1"};

val["name2"] = "Name1";

val["value1"] = "HelloWorld";

int i = 0; int s = 1;

for (i; i < que.size(); i++)

{

auto j = val.begin();

for (j; j != val.end(); j++)

{

if (j->first == que[i])

{

cout << j->second << endl;

s += 1;

}

}

if (s == 1)

{

cout << "Not Found!" << endl;

}

}

} Now, if I write else { cout << "Not Found!" << endl;} after the first if statement and delete the 2nd statement...it prints so many "Not Found!" messages...I want to print only once... CAN SOMEONE HELP ME WITH THIS ?? PLS. PROVIDE AN EXPLANATION TO THE SAME AS WELL....

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!