const char *到std :: basic_iostream [英] const char * to std::basic_iostream
本文介绍了const char *到std :: basic_iostream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个指向 const * char
缓冲区的指针及其长度,并尝试使用API(在这种情况下, AWS S3 C ++上传请求),它接受以下类型的对象:
I have a pointer to a const *char
buffer as well as it's length, and am trying to use an API (in this case, the AWS S3 C++ upload request) that accepts an object of type:
std::basic_iostream <char, std::char_traits <char>>
是否有一种简单的标准C ++ 11方法将缓冲区转换为兼容的流,最好不要实际复制了内存?
Is there a simple standard C++11 way to convert my buffer into a compatible stream, preferably without actually copying over the memory?
推荐答案
由于Igor的评论,这似乎行得通:
Thanks to Igor's comment, this seems to work:
func(const * char buffer, std::size_t buffersize)
{
auto sstream = std::make_shared<std::stringstream>();
sstream->write(buffer, buffersize);
...
uploadRequest.SetBody(sstream);
....
这篇关于const char *到std :: basic_iostream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文