String Find Last Of Function - C++ Programming Tutorial
C++ Course / Strings / String Find Last Of Function

String Find Last Of Function

BLUF: Mastering String Find Last Of Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: String Find Last Of Function

C++ is renowned for its efficiency. Learn how String Find Last Of Function enables low-level control and high-performance computing in the tutorial below.

This function scans the string to find the final character that matches any of the characters specified within the string.

Syntax

Consider two strings str1 and str2. The syntax is as follows:

Example

str1.find_last_of(str2);

Parameters

str : str is the string to be used in searching.

The position parameter specifies the starting point for the search operation.

n : The quantity of characters that serve as identifiers for the characters to be searched for.

The 'ch' parameter specifies the character to search for.

Return value

It provides the index of the initial character that differs.

Examples 1

Let's see the simple example.

Example

#include<iostream>
using namespace std;
int main()
{
string str = "I love India";
cout<< "String contains :" << str <<'\n';
cout<< str.find_last_of("love");
return 0;
             }

Output:

Output

String contains : I love India
    5

Examples 2

Let's explore a basic example where the specified starting position for the search is provided.

Example

#include<iostream>
           using namespace std;
          int main()
        {
        string str = "C++ Tutorial";
       cout<< "String contains :" << str <<'\n';
      cout<< str.find_last_of("Tutorial",3);
       return 0;
       }

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience