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