无法将二进制文件读取为浮点值 [英] Trouble reading a binary file as float values

查看:59
本文介绍了无法将二进制文件读取为浮点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在读取二进制文件时遇到浮动值问题。我必须以二进制模式读取数据,然后将每四个字节读取到一个浮点变量中。我已完成搜索,但我发现read和get函数不接受float类型。我现在应该怎么做?有人能帮帮我吗?


这是代码..

Hi all,
I''m having a trouble reading a binary file as float values.I have to read the data in binary mode, then read every four bytes into a float variable. I have done my search, but i found out that the read and get functions do not accept float type. What should i do now? Can anybody help me please?

Here is the code..

展开 | 选择 | Wrap | 行号

推荐答案

你可以使用fstream的read()函数来读取一个字节序列

http://www.cplusplus.com/reference/iostream/istream/read.html
you can use the read() function from fstream to read a sequence of bytes
http://www.cplusplus.com/reference/iostream/istream/read.html


感谢您的回复,但问题是,read函数处理char类型,我需要读取数据并将它们作为浮点类型打印到屏幕上:(
Thank you for your reply, but the problem is, the read function deals with char type, i need to read the data and tprint them into the screen as a float type :(



感谢您的回复y,但问题是,read函数处理char类型,我需要读取数据并将它们作为浮点类型打印到屏幕上:(
Thank you for your reply, but the problem is, the read function deals with char type, i need to read the data and tprint them into the screen as a float type :(



your可以通过查看大小(甚至是数组)来读/写任何对象,例如假设你有一个结构

your can read/write any object by sepcifing the size (even an array), e.g. say you have a structure

展开 | 选择 | Wrap | 行号


这篇关于无法将二进制文件读取为浮点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆