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 |
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
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 clear() This function removes the elements, becomes an empty string. Syntax Consider a string str. Syntax would be: str.clear(); Parameter This function does not contain any parameter. Return value This function does not return any value. Example Let's see a simple example of clear() function: #include<iostream> using namespace std; int main() { stringstr; cout<<?Enter some lines about javaTpoint and...
1 min read
C++ String front() This function is used to reference a first character of the string. Syntax Consider a string str. Syntax would be: char& p = str.front(); Parameter This function does not contain any parameter. Return value It is used to return a reference of the first character. Example 1 Let's see the simple example. #include<iostream> #include<string> using namespace...
1 min read
C++ String operator=() This function is used to assign a new value to the string, replacing all the current contents. 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, whose value is to be moved. ch : ch is a character...
1 min read
C++ String length() This function is used to find the length of the string in terms of bytes. This is the actual number of bytes that conform the contents of the string , which is not necessarily equal to the storage capacity. Syntax int len = s1.length(); Parameters This function contains single...
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 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 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 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
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