Ascii .txt文件到字节数组 - C++
Ascii .txt file to array of bytes - C++
如何在 c++ 中将 ascii .txt 文件转换为字节数组? 例如,给定 XYZ 坐标的.txt文件,将其转换为浮点表示的字节数组:
253.9999929 58.0428367 -21.3930063253
.9999929 59.0435773 -21.2499391255
...
转换为
bytes array[] = {
01000011,01111110,00000000,00000000,
01000010,01101000,00101011,11011101,
11000001,10101011,00100100,11100001,
00111111,01111111,11111111,10001001... etc
}
我想过将字符串中的每个数字转换为浮点数,然后提取二进制表示;但是,我不确定这是否有效。我需要使用包含 200000-1400000 行 XYZ 数据的 .txt 文件大规模执行此操作。
谢谢!
也许是这样:
struct xyz{
float x;
float y;
float z;
};
istream& operator >>(istream & is, xyz & v) {
return is >> v.x >> v.y >> v.z;
}
std::ifstream f{"floats.txt"};
vector<xyz> floats;
copy(istream_iterator<xyz>{f}, {}, inserter(floats, end(floats)));
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 将数组的地址分配给变量并删除
- 从C++本机插件更新Vector3数组
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 数组索引的值没有增加
- 将对象数组的引用传递给函数
- 为char数组调整zlib-zpipe
- 2D数组来自文本输入,中间有空格
- std::向量与传递值的动态数组
- 在c++中用vector填充一个简单的动态数组
- 使用strcpy将char数组的元素复制到另一个数组
- 使用指针从C++中的数组中获取最大值
- C++使用整数的压缩数组初始化对象
- 告诉一个 const char 数组,除了编译时 C 样式的字符串外,它不以 '