C++ String at()30 Aug 2024 | 1 min read This function is used for accessing individual characters. SyntaxConsider a string str. To find the position of a particular character, its syntax would be Parameterspos : It defines the position of the character within the string. Return valueIt returns the character specified at that position. Example 1Output: String contains Welcome to javatpoint tutorial Example shows that we can access the characters by using either the member function at() or the subscript operator[ ]. Next TopicC++ Strings |
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 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 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
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 end() This function is used to return an iterator pointing to the last character of the string. Syntax Consider a string 'str' and an iterator 'it'. Syntax would be: iterator it = str.end(); Parameter This function does not contain any parameter. Return value It returns an iterator pointing to the end of...
1 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 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 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
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