explain any four method of string class
Answers
Answer
Hello, because the choice of language is not mentioned in respective
question so the answer is according to C++'s native string class..
4 methods are as follows:-
1). std::string::size() = it returns the total size of the given string which is
equivalent to the length of the string. Here the size is in terms of
the no. of bytes required to represent that string irrespective of the
capacity of the string.
eg. string str = "hello world"; cout << str.size(); //outputs 11 as the answer
2). std::string::at() = returns the element at index passed as the parameter
& is equivalent to string_object [index_no.]
eg. string str = "hello world"; cout << str.at(4) << " " << str[4] //outputs o o
3). std::string::resize() = it resizes the given string to a specified positive
value which can be further increased or decreased.
4). std::string::swap() = it simply swaps 2 given strings so that the contents
of both strings get exchanged without any change in index values of both
strings => str1.swap(str2); it is equivalent to str2.swap(str1);
References:
for more information about std::string class please visit
for std::string::length()
https://brainly.in/question/5169390
for c strings
https://brainly.in/question/8815677