对,所以我正在玩弄内存移动数据。我在这里遇到了麻烦。我做错了什么?我已经考虑了空终止符,但它仍然没有输出我所期望的。
char buff[34] = "I will not do anything like that.";
char * protocol = "abcdefghi";
char data[44];
memcpy(data, protocol, 10);
memcpy(data + 9, buff, 34);
cout << data << endl; //abcdefghiI will not do anything like that.
cout << strlen(data) << endl; // 42
char poin[10];
memcpy(poin, data, 10);
cout << poin << endl; //abcdefghiI╠╠╠╠╠╠╠╠╠╠abcdefghiI will not do anything like that.
对于最后一个 cout,我期待的只是 abcdefghi,但正如你在上面看到的那样。任何帮助表示赞赏,谢谢!