how to use memcpy
时间: 2023-10-13 22:08:12 浏览: 74
Here is an example of how to use memcpy():
```c++
#include <iostream>
#include <cstring>
int main() {
char source[] = "Hello, World!";
char destination[50];
std::memcpy(destination, source, sizeof(source));
std::cout << "Source: " << source << std::endl;
std::cout << "Destination: " << destination << std::endl;
return 0;
}
```
Output:
```
Source: Hello, World!
Destination: Hello, World!
```
In this example, we have two character arrays: `source` and `destination`. We want to copy the contents of `source` into `destination`.
We use the `std::memcpy()` function to copy the memory from the source to the destination.
The first argument is the destination, the second argument is the source, and the third argument is the size of the source array.
After the `std::memcpy()` function is called, the contents of the `source` array have been successfully copied into the `destination` array.
阅读全文