开发者

Making a char** with std::?

开发者 https://www.devze.com 2023-03-09 07:20 出处:网络
I have an opengl function that requires a const char**. So essentially a vector of strings. I was wond开发者_Go百科ering if this could be done using the C++ Standard Library without making a vector of

I have an opengl function that requires a const char**. So essentially a vector of strings. I was wond开发者_Go百科ering if this could be done using the C++ Standard Library without making a vector of const char* which would demand heap allocation.


If you're wanting to avoid heap allocation:

const char* arrayOfStrings[] = {
    "first string",
    "second string",
    "third string"
};

And you can use arrayOfStrings as a const char**.

If you have a vector of const char*s you can just get the address of the first element to obtain a const char**:

&vec[0];

However, what do you mean when you say "using [c++ standard library]"? You say you want to "use the [C++ standard libary] without making a vector of const char*". That doesn't make much sense.

You don't need the standard library for this, please clarify your question if my answer isn't sufficient.

0

精彩评论

暂无评论...
验证码 换一张
取 消