C++ String Data()30 Aug 2024 | 1 min read 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. SyntaxConsider a string str and pointer p. Syntax would be: ParameterThis function does not contain any parameter. Return valueIt returns the pointer to an array. Example 1Output: String contains : C++ Strings This example displays the string using data() function. Example 2Output: 1245 Next TopicC++ Strings |
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
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 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 empty() This function checks whether the string is empty or not. Function returns a Boolean value either true or false. Syntax Consider a string str. Syntax would be: str.empty(); Parameter This function does not contain any parameter. Return value It returns a Boolean value either 0 or 1 depending upon the conditions....
1 min read
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
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
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
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
C++ String Assign() This functions assigns a new value to the string,replacing all its current contents. Syntax Consider two strings str1 and str2, Syntax would be : Str1.assign(str2); Parameters str : str is a string object, whose value to be assigned. subpos : It defines the position of the character which is to...
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
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