C++ - 转换标准::浮点数组的字符串
C++ - Convert std::string of float array
这个问题是C++的后续问题 - 将浮点数组转换为 std::string。
如何将std::string
转换回使用reinterpret_cast
转换为字符串的浮点数组。
从c_str()
方法获取字符串的支持数据指针。然后将其reinterpret_cast回浮点指针。
const float* array_of_floats = reinterpret_cast<const float*>(str.c_str());
int len = str.size() / sizeof(float);
通常,将二进制数据(例如浮点数数组(序列化为string
可以工作,但充其量是奇怪的,而且更可能是不明智的。 最好使用std::vector<uint8_t>
作为字节数组来保存浮动指针数据,而不是字符串的实例。
相关文章:
- 使用 jsoncpp 解析 json 数组字符串
- C++ 对象数组字符串输入在控制台上不起作用
- 插入了 C++ 数组字符串数据,但在显示输出时不显示
- 无法区分 JSON 对象/数组/字符串
- 为什么数组(字符串类型)的大小是 24 字节,带有单个空格元素
- 如何使用数组字符串进行输入验证
- (C++) 打印字符数组字符串的单词时出现问题
- 使用Back_inserter从任何位置的输入字符中使用Back_inserter进行过滤数组字符串
- C 函数反转字符数组字符串
- 如何在 c++ 中创建数组(字符串 [] )的向量
- 如何返回数组字符串的指针
- char数组字符串混淆
- 如何从字符数组字符串中提取空格
- 是否可以将 Bitset<8> 的值复制到数组字符串而不转换它们?
- C++数组字符串函数
- 如何在函数中操作字符数组(字符串)的指针,该指针在C / C ++中作为参数传递
- visual将音频文件存储到数组/字符串流C++中
- c++在char数组(字符串)上将what替换为
- 将数组字符串转换为intger c++(初学者)
- 需要设置数组字符串长度,使其恰好为13