C++ String copy()This function copies the contents of one string into another string. SyntaxSuppose str1 and str2 are two string objects, len is the length of substring. We want to copy string str1 into the string object str2 then the syntax would look like: Parameterstr2: str2 is the destination string object which retains the copied string. len: It defines the length of substring. pos: It determines the position of first character to include. Return valueIt returns the number of characters to be copied. Example 1Let's see a simple example of copying the string into another string object. Output: source string is: javatpoint tutorial destination string is: javatpoint tutorial In this example, source string contains the value "javatpoint tutorial" and we copy the source string to the destination string using copy function. Example 2Let's see a simple example of copying the string when position is passed in a parameter. Output: String contains: programs In this example, we copy the substring of string str i.e. programs to the string str1 using copy function. Example 3Let's see a simple example of copying the array of integers in vector Output: 12345 In this example, we copy the array of integers to the vector using copy function.
Next TopicC++ Strings
|
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week