New Function size() & length() :-
' size() ' & ' length() ' working of both the function are same i.e. to know the string size.
string s1 = "Dummy Input";
cout << s1.size() <<endl;
string s2 = "Dummy Output";
cout << s2.length();
11
12
New Function insert() :-
This function is used to insert string in the existing string.
string s = "Duy Input";
s.insert(2,"mm");
cout << s;
Dummy Input
New Function substr() :-
To print substring of a given string substring is used (we have to input starting index and how many character we want to print).
string s = "Dummy Input"; cout << s.substr(6,2);
//It will print 2 chars from 6th index
In
New Function begin(), end() & sort() :-
" sort() " is a inbuilt function to sort the given string and " begin() " function tells the first character of the string where as " end() " is tells the last character of the string.
string s = "zyxw"; cout << "Unsorted string: " << s <<< endl; sort (s.begin (), s.end ());
//function for sorting the string
cout << "Sorted string is: " << s;
Unsorted string: zyxw
Sorted string is: wxyz
New Function stoi() & to_string() :-
To convert string into integer " stoi() " function is used and to convert integer into string " to_string() " function is used.
string s = "140";
int x = stoi (s); //storing the converted integer value in x
cout << x + 3;
143
int x = 143;
string s = to_string (x); //storing the converted string in s
cout << s + '2';
1432
C++ Program To Implement String II
Reviewed by Beast Coder
on
March 17, 2021
Rating:
No comments: