Question 2
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
#include <string>
int main() {
std::string grade = 'A';
std::cout << grade << '\n';
return 0;
}
- A grade must be uppercase
- B std::string has no constructor taking a single char for copy-initialization; write std::string grade(1, 'A') or "A" Correct
- C cout cannot print one letter
- D char must be in double quotes everywhere
Correct Answer: Option B
Assigning later (grade = 'A';) does compile, because operator= has a char overload – only this initialization form fails.
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!