In C++, std::string::contains() returns true if a substring or character appears anywhere in the string (C++20).
It is the readable form of find(...) != npos. Include <string>.
This is a member of std::string. A string grows as you append, stores characters contiguously, and can reallocate—after growth, old iterators and references may be invalid. Prefer at() when you want bounds checks; remember find returns npos when missing.
Syntax
Pass text or a character.
C++
bool ok = s.contains("C++");
bool has = s.contains('@');
Call
What it does
s.contains(str)
True if str occurs as a substring.
s.contains(ch)
True if character ch occurs.
Needs C++20. On older modes, write s.find(x) != std::string::npos.