无法将二进制文件读取为浮点值

无法将二进制文件读取为浮点值

问题描述:

大家好,

我在读取二进制文件时遇到浮动值问题。我必须以二进制模式读取数据,然后将每四个字节读取到一个浮点变量中。我已完成搜索,但我发现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 | 行号