writing directly to std::string internal buffers

前端 未结 9 1153
猫巷女王i
猫巷女王i 2020-11-29 07:22

I was looking for a way to stuff some data into a string across a DLL boundary. Because we use different compilers, all our dll interfaces are simple char*.

Is ther

9条回答
  •  盖世英雄少女心
    2020-11-29 07:35

    As long as C++11 gives contiguous memory guaranties, in production practice this 'hacky' method is very popular:

    std::string stringToFillIn(100, 0);
    FunctionInDLL(stringToFillIn.data(), stringToFillIn.size());
    

提交回复
热议问题