C++ String back()30 Aug 2024 | 1 min read This function is used to access the last character of string. SyntaxConsider a string s. Syntax would be: ParameterThis function does not contain any parameter. Return valueThis function returns the reference of last character of the string. ExampleLet's see the simple example to add a mew character at the end of the string Output: BTech in computer science In this example, '.' character has been replaced by the '!' character by using back function. Next TopicC++ Strings |
C++ String rfind() This function is used to find the string for the last occurrence of the sequence specified by its arguments. Syntax Consider a string 'str' and key string 's'. Syntax would be: str.rfind(s); str.rfind(s,pos); str.rfind(s,pos,n); str.rfind(ch); Parameter str : str is a string object which is used in searching. pos : It defines the...
1 min read
C++ String Find() This function is used for finding a specified substring. Syntax Consider two strings str1 and str2. Syntax would be : str1.find(str2); Parameters str : String to be searched for. pos : It defines the position of the character at which to start the search. n : Number of characters in a...
1 min read
C++ String operator[]() This function is used to get a character at position pos in the string. Syntax Consider a string 'str' and character 'ch' at position 'pos'. Syntax would be: char ch = str.operator[ ](pos); Parameter pos: It defines the position of character which is to be retrieved. Return value This function returns...
1 min read
C++ String crend() The crend() function stands for reverse end. It points to the first character of string and returns constant reverse iterator. Syntax Consider a string s. Syntax would be: const_reverse_iterator itr=s.crendO; Parameter It does not contain any parameter. Return value It returns a constant reverse iterator to the reverse end of...
1 min read
C++ String append() This function is used to extend the string by appending at the end of the current value. Syntax Consider string str1 and str2. Syntax would be : Str1.append(str2); Str1.append(str2,pos,len); Str1.append(str2,n); Parameters str : String object which is to be appended in another string object. pos : It determines the position of the...
1 min read
C++ String find_last_of() This function searches the string for the last character that matches any of the character specified in the string. Syntax Consider two strings str1 and str2. Syntax would be : str1.find_last_of(str2); Parameters str : str is the string to be used in searching. pos : It defines the position at...
1 min read
C++ String shrink_to_fit() This function reduces the capacity of the string and makes it equal to its size. Syntax Consider a string str. Synatx would be: str.shrink_to_fit(); Parameter It does not contain any parameter. Return value It does not return any value. Example 1 Let's see the simple example. #include<iostream> using namespace std; int main() { string str="C++ Programming"; cout<<str.capacity()<<'\n'; str.shrink_to_fit(); cout<<str.capacity(); return 0; } Output: 15 15 In this...
1 min read
C++ String crbegin() The crbegin() function stands for 'reverse beginning'. This function references to the last character of the string. Syntax Consider a string str. Syntax would be: str.crbegin(); Parameter This function does not contain any parameter. Return value This function returns the constant iterator pointing to the last character of the string. Example 1 Let's...
1 min read
C++ String empty() This function checks whether the string is empty or not. Function returns a Boolean value either true or false. Syntax Consider a string str. Syntax would be: str.empty(); Parameter This function does not contain any parameter. Return value It returns a Boolean value either 0 or 1 depending upon the conditions....
1 min read
C++ String begin() This function gives a reference to the first element. Syntax Consider a string 's' and iterator 'it'. Syntax would be: iterator it = s.begin(); Parameter This function does not contain any parameter. Return value This function does not return any value. Example 1 Let's see the simple example of begin() function. #include<iostream> using namespace std; int...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India