LearnFrenzy
Sign in Take a free test

std::string · Predict the Output · Question 12

starts_with, ends_with and contains Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

What is the output of the following program, compiled as C++23?

main.cpp
#include <iostream>
#include <string>

int main() {
    std::string f = "report_2026.pdf";
    std::cout << f.starts_with("rep") << f.starts_with('R') << f.ends_with(".pdf")
              << f.contains("2026") << f.contains('x') << '\n';
    return 0;
}
  • A 10110 Correct
  • B 11110
  • C 10111
  • D 00110
Correct Answer: Option A

The checks are case-sensitive, so 'R' does not match 'r'. contains (C++23) accepts a string or a character.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links