将char *转换为std :: vector [英] Cast char* to std::vector

查看:237
本文介绍了将char *转换为std :: vector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有快速(CPU)方法将 char 数组转换为 std :: vector< char>

Is there a fast (CPU) way to cast a char array into a std::vector<char>?

我的函数看起来像这样:

My function looks like this:

void someFunction(char* data, int size)
{
    // Now here I need to make the std::vector<char>
    // using the data and size.
}


推荐答案

这里的任何东西,但你可以很容易地从C字符串构造一个向量:

You can't "cast" anything here, but you can easily construct a vector from the C string:

std::vector<char> v(data, data + size);

这将创建一个副本。

这篇关于将char *转换为std :: vector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆