C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C++ String resize()This function is used to resize the string to the length of k characters. SyntaxConsider a string object str. To resize the string object, syntax would be : str.resize(k,c); ParametersThis function contains two parameters.
If k is shorter than the length of the string, string length shortened to the length specified by k, removing all the characters beyond k. If k is larger than the length of the string, string length extended to the length specified by k. Return valueIt does not return any value. Example 1When k is shorter than length of the specified string. #include<iostream> using namespace std; int main() { string str= "TheDeveloperBlog"; cout<<"String is :"<<str<<?\n?; str.resize(4); cout<<"After resizing, string is "<<str; return 0; } Example 2When k is greater than the length of the specified string. #include<iostream> using namespace std; int main() { string str ="TheDeveloperBlog"; cout<<"String value is :"<<str<<'\n'; str.resize(19,"tutorial"); cout<<"After resizing, string value is :"<<str; return 0; } Output: String value is TheDeveloperBlog After resizing, string value is TheDeveloperBlog tutorial
Next TopicC++ Strings
|