← Quiz: Strings in C++: all 10 questions
Quiz: Strings in C++ · Question 9 of 10
What does this print? (code)
What does this print?
#include <iostream>
#include <string>
using namespace std;
int main() {
string s = "C++";
s.insert(0, "Learn ");
s.erase(s.size() - 1);
cout << s << s.size();
return 0;
}
- A.Learn C++9
- B.Learn C+8
- C.Learn C7
- D.Learn C++8
Answer & explanation
Correct answer: Learn C+8
After insert the string is "Learn C++" (9 characters). erase(8) removes everything from index 8, the last '+', leaving "Learn C+" with size 8.
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 →