[英]C++ - Convert std::string of float array
從c_str()
方法獲取字符串的后備數據指針。 然后將其reinterpret_cast返回到float指針。
const float* array_of_floats = reinterpret_cast<const float*>(str.c_str());
int len = str.size() / sizeof(float);
通常,將二進制數據(例如浮點數數組)序列化為string
可以的,但充其量是很奇怪的,更不建議這樣做。 最好使用std::vector<uint8_t>
作為字節數組來保存浮動指針數據而不是字符串實例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.