Javatpoint Logo
Javatpoint Logo

wmemmove() function in C++

C++ allows developers to develop strong applications, which has been hailed as among the most powerful and flexible programming languages in the market. Among many C++ functions, wmemmove() is a useful technique for handling wideness in block movement in similar arrays. It is an in-depth tutorial where you will discover about remove (), how it can be used and illustrative examples with the output

Syntax:

Let's first dissect the syntax of wmemmove() to gain a better understanding of its components:

dest: The destination addresses in the memory at which the information should be placed.

src: Identification of a pointer to a data source for copying.

count: The count of characters to be copied.

Wmemmove() is notably useful when it comes to cases of overlapping source and destination memory areas, making sure that data being copied remains accurate.

Example:

Let us get to a practical example to understand why wmemmove() appraisal is important. Let us say that we got a very long string, which means a sentence in simple words, and we want to move some part of it somewhere in the same line.

Output:

Original String: Programming is fascinating.
Modified String: fascinating.

Breaking Down the Code:

Include Necessary Headers:

Start with #include,<iostream>, for input and output; and #include,<cwchar>.

Declare the Main Function:

Establish the basic function and the entry point for our program.

Initialize the Original String:

Assign an array with large string name originalString, having the sentence "programming is interesting".

Display the Original String:

Display the originally supplied string, utilizing wprintf().

Specify the Number of Characters to Move:

Now, set the variable count to the number of wide characters we are going to move.

Create a Destination Array:

Specify enough room for the moved characters in the destinationString.

Utilize wmemmove():

The crucial step is the use of remove (originalString + 12), which moves a specified character number from the original string into the destination array.

Null-Terminate the Destination String:

Correctly process it only if the destination string has been null terminated in order.

Display the Modified String:

Output the updated string using wprintf().

Example 1:

Output:

Original String: C++ is powerful.
Modified String: is powerful.C++

Breaking Down the Code:

Header Inclusions:

The program includes two standard C++ headers: Iostream for input and output operations, CWChar for wide character functions.

Main Function:

The main() function becomes an entry point as the executable file starts with it as discussed in the previous paragraphs.

Original String Definition:

There is a broad type of object called originalString with an input as "C++ is mighty".

Display Original String:

Wprintf() prints out the original string to the console.

Number of Characters to Move:

Six wide characters are shifted by adjusting the variable count to 6.

Destination Array Creation:

The shifted characters are stored in an array called destinationString allocated a sufficient length of 20 characters that can accommodate them all.

wmemmove() Function Usage:

It uses the wmemmove() function to move characters to the left in the destination array. Position count starts with the destination, which is the copied string, from the source, which is the primary string.

Display Modified String:

Wprintf() outputs the modified string, which now consists of the shifted characters to the console.

Program Termination:

It indicates that the program has successfully ended with a return zero; statement.

Example 2:

Output:

Original String: Memory overlap is handled by wmemmove.
Modified String: overlap is ioverlap.

Breaking Down the Code:

Header Inclusions:

The program includes two standard C++ headers: Stream input and output (<iostream>) and wide character functions (<cwchar>).

Main Function:

The main() function is the door through which the program enters into existence.

Original String Definition:

The string originalString with the given value memory overlap is handled by wmemmove is the wide string.

Display Original String:

Wprintf() prints out the original string to the console.

Number of Characters to Move:

It specifies that ten wide characters will be the variable count.

Destination Array Creation:

After that, an array destinationString large enough(50 wide character slots) is allocated for transferring the moved characters.

wmemmove() Function Usage:

The wmemmove() function is used to shift characters in the destination array. Position 10 is the origin, while position 5 appears in the destination's array. It defines a counter for the number of characters that are moved.

Null-Termination of Destination String:

Printing of the destination string is successful when it's null-terminated.

Display Modified String:

Wprintf() is used to display the new, modified string which contains the moved characters.

Program Termination:

Return 0; is a statement that indicates that the program has ended successfully.

Example 3:

Output:

Original String: Handling null-terminated strings.
Modified String: null-term

Breaking Down the Code:

Header Inclusions:

The program includes two standard C++ headers: Input and Output using <iostream>, and Wide Characters with the help of <cwchar>.

Main Function:

Main() function being the entrance point for the program.

Original String Definition:

We declare a string called originalString with content "Handling null-terminated strings".

Display Original String:

Through wprintf() function, the original string is displayed on the console.

Number of Characters to Move:

It will move nine (wide) characters or WCHARS.

Destination Array Creation:

The moved characters are placed into an array called destinationString that is of adequate size (50 wide characters).

wmemmove() Function Usage:

Wmemmove() function moves characters from the 7th place in the original string to the destination array. This variable indicates how many characters are set to be moved.

Null-Termination of Destination String:

The null terminates the destination string to make sure for proper printing.

Display Modified String:

It displays the modified string with the already moved letters to the console through the wprintf() function.

Program Termination:

The return 0; indicates that the program has finished without errors.

However, wmemmove() has some advantages compared to memmove(). For example, there is no need to use it specifically for wide characters. Unlike memmove(), wmemmove is a must tool for those who are concerned about issues of internationalization and localization where wide characters plays a major role in it.

Conclusion:

In the dynamically evolving world of C++ programming, the wmemmove() function is proof in itself that C++ is efficient and flexible. In our end, it is evident that wmemmove() provides accurate and dependable maneuvering of wide characters. The reason why this tool is important to the developer dealing with multilingual text processing is that it can cope with overlapping memory regions and work with wide characters. Programmers armed with an in-depth knowledge of wmemmove() can raise their code, which ensures the smooth movement of data within the wide character arrays, thus making their C++ strong.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA