Objectives :

  • Using Keyword :
    •  string_object.find() function
    • size_t of string class
    • compared with "memchr(...)" function of cstring library.
  • Functions :
    • C++ string class : find()
    • C string.h library : strchr(), memchr() , and strlen()

  • File Name : compare_find_memchr1.cpp
  • Code : compare_find_memchr1.txt

The functions like find(..) of string class in C++ and memchr() or strchr() of C, are designed to search a matching "string" or a character respectively. The function sring_object.find(a string), has a built-in locator, which will mark the occurrence of first character of the search-string in the target-string.


Step: 1 Create a source file.

Step: 2 Edit and save Source file

Step: 3 Runtime Views:

Step: Brief discussion:

The syllable size_t, represent unsigned (only positive integers) data type which is designed to apprehend the  amount of memory requires, expressed in units of `char'. An integral data type would be returned by the language operator sizeof and is defined in the <cstring> header file. The function strlen() to returns a number (length of a character array) of  "significant" characters are in a string. (Please review this example : size_t_size_type1.htm)

Unsigned integral type ( to be deleted later)

size_t corresponds to the integral data type returned by the language operator sizeof and is defined in the <cstring> header file (among others) as an unsigned integral type.

<cstring>, it is used as the type of the parameter num in the functions memchr, memcmp, memcpy, memmove, memset, strncat, strncmp, strncpy and strxfrm, which in all cases it is used to specify the maximum number of bytes or characters the function has to affect.

It is also used as the return type for strcspn, strlen, strspn and strxfrm to return sizes and lengths.