Question 19
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 = "abc";
s.resize(6, '.');
std::string t;
t.assign(3, '=');
t.append(2, '>');
s.resize(4);
std::cout << s << ' ' << t << ' ' << s.size() + t.size() << '\n';
return 0;
}
- A abc. ===>> 9 Correct
- B abc... ===>> 11
- C abc. ===> 8
- D abc ===>> 8
Correct Answer: Option A
resize(6, '.') pads to "abc...", resize(4) cuts it back to "abc.". assign(3, '=') and append(2, '>') build "===>>".
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!