Question 5
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <iostream>
#include <string>
int main() {
std::string s = "abcdef";
s.insert(3, "XYZ");
s.erase(1, 2);
s.erase(s.size() - 2);
std::cout << s << '\n';
return 0;
}
- A aXYZd Correct
- B aXYZde
- C abXYZd
- D aXYde
Correct Answer: Option A
"abcXYZdef" → erase 2 chars at 1 → "aXYZdef" → erase from size − 2 to the end → "aXYZd".
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!