C + + 's substr () function

Source: Internet
Author: User

  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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.