std::string转IBuffer

c++/cx实现std::string转IBuffer

using namespace Concurrency;
using namespace Windows::Storage;
using namespace Windows::Storage::Streams;

IBuffer^ GetBufferFromString(const std::string &content)
{
	int len = content.size();
	Platform::Array<byte>^ arr = ref new Platform::Array<byte>(len);
	for (int i = 0; i < len; i++)
	{
		arr[i] = content[i];
	}

	InMemoryRandomAccessStream^ memoryStream = ref new InMemoryRandomAccessStream();
	DataWriter^ dataWriter = ref new DataWriter(memoryStream);
	dataWriter->WriteBytes(arr);
	return dataWriter->DetachBuffer();
}

猜你喜欢

转载自blog.csdn.net/auccy/article/details/82762081