Strings In Depth12 / 15
Up next

Take a string_view

#include <print>
#include <string>
#include <string_view>

// string_view binds to both a literal and a std::string
std::size_t count_chars(std::string_view s) {
    return s.size();
}

int main() {
    std::string owned = "there";
    std::println("{}", count_chars("hi"));
    std::println("{}", count_chars(owned));
}
What you're solving

one parameter accepts literals and strings