C++ String cend()30 Aug 2024 | 1 min read This function gives a reference to the last character of the string. Difference b/w end() and cend()The only difference between end() and cend() function is, cend() returns the constant iterator pointing to the constant value. SyntaxConsider a string str. Syntax would be: ParameterThis function does not contain any parameter. Return valueThis function returns the reference pointing to the last element of the string. Example 1Output: mango is my favorite fruit This example displays the string using cbegin() function. Example 2Output: 12345 This example displays the list using cbegin() and cend() function. Next TopicC++ Strings |
C++ String at() This function is used for accessing individual characters. Syntax Consider a string str. To find the position of a particular character, its syntax would be str.at(pos); Parameters pos : It defines the position of the character within the string. Return value It returns the character specified at that position. Example 1 #include<iostream> using namespace...
1 min read
C++ String pop_back() This function is used to remove a last character of a string, decreasing its length by one. Syntax Consider a string str. Syntax would be : str.pop_back(); Parameters This function does not contain any parameter. Return value This function does not return any value. Example 1 Let's see the simple example. #include<iostream> using namespace std; int...
1 min read
C++ String find_last_not_of() This function is used to search the string for the last character that does not match with any of the character specified in the string. Syntax Consider two strings str1 and str2. Its syntax would be : str1.find_last_not_of(str2); Parameters str : str is the string to be used in...
1 min read
C++ String erase() This function removes the characters as specified, reducing its length by one. Syntax Consider a string str. Syntax would be: str.erase(pos,len); str.erase(itr); str.erase(first,last); Parameter pos :It defines the position of the character which is to be removed. len :It defines the number of characters to be erased. Itr : It is an iterator...
1 min read
C++ String replace() This function replaces the portion of string that begins at character position pos and spans len characters. Syntax Consider two strings str1 and str2. Syntax would be: str1.replace(pos,len,str2); Parameters str : str is a string object, whose value to be copied in another string object. pos : pos defines the...
2 min read
C++ String rend() The rend() function stands for reverse end. This function points to the first character of the string. Syntax Consider a string 'str' and reverse iterator 'ritr'. Syntax would be: reverse_iterator ritr = str.rend(); Parameter This function does not contain any parameter. Return value It returns a reverse iterator pointing to 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 Data() This function copies the characters of the string into an array. It returns the pointer to an array obtained from the conversion of string into array. Syntax Consider a string str and pointer p. Syntax would be: const char* p=str.data(); Parameter This function does not contain any parameter. Return value It...
1 min read
C++ String push_back() This function is used to add new character ch at the end of the string, increasing its length by one. Syntax Consider a string s1 and character ch . Syntax would be : s1.push_back(ch); Parameters ch : New character which is to be added. Return value It does not return any...
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
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