Is there a reverse function for strstr

后端 未结 17 2355
闹比i
闹比i 2020-12-18 18:28

I am trying to find a similar function to strstr that searches a substring starting from the end towards the beginning of the string.

17条回答
  •  不思量自难忘°
    2020-12-18 19:32

    You can use standard algorithm std::find_end for this purpose. For example

        char s[] = "What is the last word last";
        char t[] = "last";
    
        std::cout << std::find_end( s, s + sizeof( s ) - 1, t, t + sizeof( t ) -1 )
                  << std::endl;
    

提交回复
热议问题