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 rbegin() The rbegin() function stands for reverse beginning. This function is used to point to the last character of the string. Syntax Consider a string str. Syntax would be: reverse_iterator itr = str.rbegin(); Parameter This function does not contain any parameter. Return value It returns the reverse iterator pointing to the last...
1 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 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 max_size() This function returns the maximum length the string can reach due to known system. Syntax Consider a string str. Syntax would be: str.max_size(); Parameters It does not contain any parameter. Return value This function returns the maximum length that string can reach. Example 1 Let's see the simple example. #include<iostream> using namespace std; int main() { string str...
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 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 capacity() This function gives the current size of the allocated space for the string. Capacity of the string is not necessarily equal to the size or length of the string. If it is greater, it means extra space is allocated for other string operations. Syntax Consider a string...
1 min read
C++ String reserve() This function requests a change in capacity. Syntax Consider a string str and l is planned length of the string. Its syntax would be: str.reserve(l); Parameter l is the planned length for the string Note: capacity of the string can be greater than or equal to 'l'. Return value It does not...
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 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
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