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 c_str() This function returns a pointer to an array that contains null terminated sequence of characters. Syntax Consider a string str. Syntax would be: str.c_str(); Parameter It does not contain any parameter. Return value It returns a pointer to the c-string representation of the string object's value. Example Let's see the simple example. #include<iostream> #include<cstring> #include<string> using...
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 swap() This function is used to exchange the values of two string objects. Syntax Consider two strings s1 and s2 , we want to exchange the values of these two string objects. Its syntax would be : s1.swap(s2) Parameters It contains single parameter, whose value is to be exchanged with...
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 cbegin() It gives a reference to the first element of the string. Difference b/w cbegin() and begin() The only difference between cbegin() and begin() is cbegin() returns the constant iterator pointing to the constant value. Syntax Consider a string str. Its syntax would be: str.cbegin(); Parameter This function does not contain...
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 find_first_not_of() This function is used to search the string for the first character that does not match any of the characters specified in the string. Syntax Consider two strings str1 and str2. Syntax would be : str1.find_first_not_of(str2); Parameters str : str is the string to be used in searching. pos :...
1 min read
C++ String size() This function is used to return the length of the string in terms of bytes. It defines the actual number of bytes that conform to the contents of the string object which is not necessarily equal to the capacity. Syntax Consider a string object named...
1 min read
C++ String operator+=() This function is used to extend the string by appending new characters at the end of the string. Syntax Consider two strings str1 and str2. Syntax would be : str1.operator+=(str2); str1.operator+=(ch); str1.operator+=(const char* s); Parameter str2: str2 is a string object which is to be appended. s: s is a pointer to...
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