C++ String size()30 Aug 2024 | 1 min read 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. SyntaxConsider a string object named as 'str'. To calculate the size of this string object, its syntax would be : ParametersThis function does not contain any parameter. Return ValueThis function returns the number of characters present in the string object. Example 1Output: length of the string is : 34 In this example, str is a string object containing value "Welcome to the javatpoint tutorial". We calculate the length of the string using 'size' function. Next TopicC++ Strings |
string resize() function
C++ String resize() This function is used to resize the string to the length of k characters. Syntax Consider a string object str. To resize the string object, syntax would be : str.resize(k,c); Parameters This function contains two parameters. k : k is number of characters specified in the first parameter. It resizes...
1 min read
string insert() function
C++ String insert() This function is used to insert a new character, before the character indicated by the position pos. Syntax Consider two strings str1 and str2, pos is the positon. Syntax would be : str1.insert(pos,str2); Parameters str : String object to be inserted in another string object. pos : It defines the...
2 min read
string reserve() function
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
string cend() function
C++ String cend() 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. Syntax Consider a string str. Syntax would be: str.cend(); Parameter This function does not contain...
1 min read
string at() function
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
string find() function
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
string find_last_of() function
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
string append() function
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
string assign() function
C++ String Assign() Function In the C++ programming language, the assign() function is commonly utilized to assign new content to a string by replacing its existing content. This function gives us many overloaded versions that allow us to copy the data from another string, C-string, character...
5 min read
string find_first_of() function
C++ String find_first_of() Function In the C++ programming language, the is a simple and effective string-searching function. It is commonly utilized to locate the first occurrence of any character from a given set of characters within a string. It scans or checks the string from...
6 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