SUBSTR () function

Source: Internet
Author: User

Substr

Defined in header file <string>

String substr (size_t pos = 0, size_t len = npos) const;
Copies a substring, which is required to start at the specified position and has the specified length.
If the pos equals the string length, an empty string is returned, and if the POS is greater than the string length, an exception is thrown.
If Len is greater than the string length, [Pos,size ()] is returned.

parameter
pos-Start copying from this location
Len-copy len length string
return value
return string containing [POS, Len ]
example

String::substr#include <iostream> #include <string>int main () {  std::string str= "We think in generalities, but we live in details. ";                                           (quoting Alfred n. Whitehead)  std::string str2 = str.substr (3,5);     "Think"  std::size_t pos = Str.find ("Live");      Position of "live" in str  std::string STR3 = Str.substr (POS);     Get from "live" to the end  std::cout << str2 << ' << str3 << ' \ n ';  return 0;}

Think live in details.

  

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.