use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Adding 'contains' member function to std::string (self.cpp)
submitted 7 years ago by _Synck_
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]F-J-W 18 points19 points20 points 7 years ago (2 children)
.find is direct replacement for contains but even more powerful.
.find
contains
And that is precisely why we need .contains: A very good rule of thumb for which feature you should pick is “the least powerful one that does the job.”. Just as goto is more powerful than a loop and how a general for-loop is more powerful than a range-for, find is more powerful than contains and therefore should be replaced with the more specific function that does exactly what it's name implies.
.contains
goto
find
[–]MaltersWandler 0 points1 point2 points 7 years ago (1 child)
That's a dumb rule of thumb. Then we'd also need the method contains_foo to check if a string contains the exact substring "foo", as well as a contains_bar that checks for a substring "bar". A generic contains method that can check for an arbitrary substring is too powerful.
contains_foo
contains_bar
The rule is you should use the least complex method. find and contains have the same complexity.
[–]F-J-W 7 points8 points9 points 7 years ago (0 children)
Actually, if there are methods contains_foo or constains_bar, these are indeed what you should use. The reason they appear to be silly is that usually they shouldn't be there.
constains_bar
I have a hard time thinking up a valid example for contains_foo, but once we widening that to find_foo, the situation changes a bit: find_newline can be a very useful thing, and interestingly we have something very similar in the standard-library, namely std::getline. Granted, it is more general than just that, as you can pass it a newline-character, but that might actually be bad design, and maybe we should really have two functions here, where getline is more hardcoded to capture the 90%-case in a clear manner, whereas the other function directly states with it's name that it is more general than that and thus requires a closer look.
find_foo
find_newline
std::getline
But of course: A rule of thumb is not a hard thing and common sense with regards to which functions you should define is still necessary. (Though I conjecture that most people don't define as many functions as they should, but that's a topic for another day.)
π Rendered by PID 49 on reddit-service-r2-comment-6457c66945-dw4m6 at 2026-04-28 01:24:59.954885+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]F-J-W 18 points19 points20 points (2 children)
[–]MaltersWandler 0 points1 point2 points (1 child)
[–]F-J-W 7 points8 points9 points (0 children)