substr () function
Note: string str = "Hello";
substr (0,4) = "Hell", does not contain the output of the 4th-bit element, and the strlen function outputs the length of the Terminator "" ".
Programming Example: Enter a line of string to find the same and longest string that appears in it, outputting it and the position of the initial letter. For example "ASCSCD", the output is SC and 2.
1 intMain ()2 {3 stringStr,tep;4cout <<"Input string:"<<Endl;5CIN >>str;6cout << Str.substr (0,5) <<Endl;7 intn =str.length ();8 for(inti = n-1; i >1; i--)9 {Ten for(intj =0; J < N; J + +) One { Asize_t T =0; -size_t num =0; -Tep = Str.substr (j, I);//The element that takes a substring from large to small, excluding the position of I the -t = Str.find (TEP);//Positive Order Lookup -num =Str.rfind (TEP); - if(t! =num) + { -cout << Tep <<" "<< T +1<<Endl; + Break; A } at } - } - return 0; -}
C + + 's substr () function