Fork me on GitHub

Project Notes


A closer look at the find function for strings in C++.


std::string::find Searches the string for the first occurrence of the sequence specified by its arguments:

  • string (1) : size_t find (const string& str, size_t pos = 0) const noexcept;
  • c-string (2) : size_t find (const char* s, size_t pos = 0) const;
  • buffer (3) : size_t find (const char* s, size_t pos, size_type n) const;
  • character (4) : size_t find (char c, size_t pos = 0) const noexcept;

Running the Examples

See example.cpp for details. A makefile compiles and runs the examples:

$ make
c++ -std=c++17 -g -Wall -O3    example.cpp   -o example
'needle' #1 found at: 14
'needle' #2 found at: 44

Credits and References

About LCK#160 C++
Project Source on GitHub Return to the Project Catalog

This page is a web-friendly rendering of my project notes shared in the LittleCodingKata GitHub repository.

LittleCodingKata is my collection of programming exercises, research and code toys broadly spanning things that relate to programming and software development (languages, frameworks and tools).

These range from the trivial to the complex and serious. Many are inspired by existing work and I'll note credits and references where applicable. The focus is quite scattered, as I variously work on things new and important in the moment, or go back to revisit things from the past.

This is primarily a personal collection for my own edification and learning, but anyone who stumbles by is welcome to borrow, steal or reference the work here. And if you spot errors or issues I'd really appreciate some feedback - create an issue, send me an email or even send a pull-request.