Question 9
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
#include <string>
int main() {
const std::string base = "file";
base.push_back('1');
std::cout << base << '\n';
return 0;
}
- A push_back takes a string
- B base is const, so non-const members such as push_back cannot be called; make a non-const copy Correct
- C '1' must be "1"
- D const strings cannot be printed
Correct Answer: Option B
std::string name = base + '1'; builds the new text without modifying the constant.
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!