← Quiz: Strings in C++: all 10 questions
Quiz: Strings in C++ · Question 5 of 10
What does this print? (code)
What does this print?
#include <iostream>
#include <sstream>
using namespace std;
int main() {
stringstream ss("4 5 x 6");
int v, sum = 0;
while (ss >> v) sum += v;
cout << sum;
return 0;
}
- A.15
- B.9
- C.4
- D.0
Answer & explanation
Correct answer: 9
Reading stops at "x" because it is not a number, so only 4 + 5 are added.
Can you get the rest right without peeking?
Take the timed Quiz: Strings in C++ quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →