C++ Foundations·Practice drills 4

Drill 8: Write a test — The standard library (STL)

Write one test you would add for this example.

Intermediate 5 min read Lesson 88 of 300 Challenge included
What you will be able to do
  • Write one test you would add for this example.

Practice task

Write one test you would add for this example.

stl.cppC++
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main() {
    std::vector<std::string> lessons = {"HTML", "CSS", "Git"};
    std::sort(lessons.begin(), lessons.end());

    for (const auto& lesson : lessons) {
        std::cout << lesson << "\n";
    }

    auto it = std::find(lessons.begin(), lessons.end(), "CSS");
    std::cout << (it != lessons.end() ? "found" : "missing") << "\n";
}
Your turn

Write your answer

Easy

Write one test you would add for this example.

TEXT · starter
Your answer…
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 88 of 300 · 0% of course