substr(): This function gets a substring of the given string from a specified
position of fixed length. This function returns the new string
Parameters:
__pos – Index of first character (default 0).
__n – Number of characters in substring (default remainder).
Syntax:
str.substr(__pos, __n)
For Example:
str = "abcdef"
str.substr(0,2) = > It returns "ab".
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){string str = "abcdef";cout << str.substr(0, 2) << "\n";return 0;}
No comments:
Post a Comment