C++ memmove 学习

memmove,将num字节的值从源指向的位置复制到目标指向的内存块。

允许目标和源有重叠。

当目标区域与源区域没有重叠则和memcpy函数功能相同。

宽字符版本是wmemmove,安全版本加_s;

#include "stdafx.h"
#include

using namespace std;

int main(int argc, char* argv[])
{
	setlocale(LC_ALL, "chs");

	char str1[7] = "aabbcc";
	cout << str1 << endl;

	memmove(str1 + 2, str1, 4);
	cout << str1 << endl;

	wchar_t str2[] = L"123456789";
	printf("%ls\n", str2);
	wmemmove(str2 + 4, str2 + 3, 3); // copy from [δεζ] to [εζη]
	printf("%ls\n", str2);
	wmemmove(str2, str2 + 3, 3);
	wcout << str2 << endl;

	char str3[] = "0123456789";
	printf("Before: %s\n", str3);
	memmove_s((str3 + 1), strnlen(str3 + 1, 10), str3, 5);
	printf_s(" After: %s\n", str3);

	return 0;
}

C++ memmove 学习_第1张图片
 

要能输出wchar_t类型,需要这句,

    setlocale(LC_ALL, "chs");

你可能感兴趣的:(VC++,memmove,wmemmove,memmove_s)