Exam CPP Topic 10 Question 54 Discussion
Actual exam question for C++ Institute's CPP exam
Question #: 54
Topic #: 10
Question #: 54
Topic #: 10
What happens when you attempt to compile and run the following code?
# include <iostream>
# include <map>
# include <vector>
# include <sstream>
# include <string>
using namespace std;
int main() {
int t[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector<int> v(t, t + 10);
map<int, string> m;
for (vector<int>::iterator i = v.begin(); i != v.end(); i++) {
stringstream s;s << *i << *i;
m.insert(pair<int, string>(*i, s.str()));
}
pair<map<int, string>::iterator, map<int, string>::iterator> range;
range = m.equal_range(6);
for (map<int, string>::iterator i = range.first; i != range.second; i++) { cout << i?>first << " ";
}
return 0;
}
# include <iostream>
# include <map>
# include <vector>
# include <sstream>
# include <string>
using namespace std;
int main() {
int t[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector<int> v(t, t + 10);
map<int, string> m;
for (vector<int>::iterator i = v.begin(); i != v.end(); i++) {
stringstream s;s << *i << *i;
m.insert(pair<int, string>(*i, s.str()));
}
pair<map<int, string>::iterator, map<int, string>::iterator> range;
range = m.equal_range(6);
for (map<int, string>::iterator i = range.first; i != range.second; i++) { cout << i?>first << " ";
}
return 0;
}
Suggested Answer: E Vote an answer
by Zoe at Jul 18, 2026, 10:56 AM
0
0
0
10
Comments
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Report Comment
Commenting
You can sign-up / login (it's free).