Skills101
← All practice quizzes

Quiz: Strings in C++

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

Everything you need from std::string for exams and coding rounds — searching, replacing, comparing, reading full lines with getline, splitting and converting with stringstream, and the standard string problems.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What does this print?

    #include <iostream>
    #include <string>
    using namespace std;
    int main() {
        string s = "placement";
        cout << s.substr(2, 3);
        return 0;
    }
    
  2. Question 2

    What does find return when the text is not found?

  3. Question 3

    What does this print?

    #include <iostream>
    #include <string>
    using namespace std;
    int main() {
        cout << (string("Mango") < string("apple"));
        return 0;
    }
    
  4. Question 4

    After cin >> n;, why does getline(cin, line); often return an empty string?

  5. Question 5

    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;
    }
    
🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →