#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
char jklmnop[ ] = "jklmnop";
char buffer1[7] = {0};
char buffer2[7] = {0};
memcpy_s(buffer1, sizeof(buffer1), jklmnop,
min(sizeof(buffer1), sizeof(jklmnop)));
buffer1[6] = '\0';
cout << buffer1 << " "; // jklmno
memcpy_s(buffer2, sizeof(buffer2), jklmnop,
min(sizeof(buffer1), sizeof(buffer2)));
buffer2[6] = '\0';
cout << buffer1 << " "; // jklmno
cout << buffer2 << " "; // jklmno
memmove_s(buffer2, sizeof(buffer2), jklmnop,
min(sizeof(buffer1), sizeof(buffer2)));
buffer2[6] = '\0';
cout << buffer1 << " "; // jklmno
cout << buffer2 << " "; // jklmno
cout << endl;
return 0;
}
// Output: jklmno jklmno jklmno jklmno jklmno
References:http://en.cppreference.com/w/c/string/byte/memcpy
http://en.cppreference.com/w/c/string/byte/memmove
No comments:
Post a Comment