写一个结构 [英] Writing a structure

查看:78
本文介绍了写一个结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在c ...中编写一个文件结构...就像在c ++中一样...... ??

是否使用fwrite ??

thanx

glen

解决方案



" Glen" < GL ******** @ yahoo.co.in>在消息中写道

新闻:eb ************************** @ posting.google.c om ...

是否可以将结构写入c中的文件...就像在c ++中一样......?


是的。

是否使用fwrite ??




这就是你的意思''用来写一个精确的二进制文件

图片,是的。另一种方法是写一个

a文本版,一次一个成员。


-Mike


< blockquote>

" Glen" < GL ******** @ yahoo.co.in>在消息中写道

新闻:eb ************************** @ posting.google.c om ...

是否可以将结构写入c中的文件...就像在c ++中一样......?


是的。

是否使用fwrite ??




这就是你的意思''用来写一个精确的二进制文件

图片,是的。另一种方法是写一个

a文本版,一次一个成员。


-Mike


< blockquote> Mike Wahler写道:

" Glen" < GL ******** @ yahoo.co.in>在消息中写道
新闻:eb ************************** @ posting.google.c om ...

是否使用fwrite ??



这就是你用来写一个精确的二进制图像,是的。另一种方法是写一个文本版本,一次一个成员。




第二个选项会更好,因为,AFAIK是一个精确的二进制图像

可能会遇到结构成员大小的问题,

编译器为结构成员选择的对齐方式

甚至是byte-endianness,如果输出文件要在不同的平台上使用。


我可能错了,想想,我很乐意如果我是在这里纠正。


-

= - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =
$ b $bRogérioBrito - rb****@ime.usp.br - http://www.ime.usp.br/~rbrito

= - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =


Is it possible to write a structure to a file in c...as in c++...??
is it using fwrite??
thanx
glen

解决方案


"Glen" <gl********@yahoo.co.in> wrote in message
news:eb**************************@posting.google.c om...

Is it possible to write a structure to a file in c...as in c++...??
Yes.
is it using fwrite??



That''s what you''d use to write an exact binary
image, yes. Another way would be to write
a textual version, one member at a time.

-Mike



"Glen" <gl********@yahoo.co.in> wrote in message
news:eb**************************@posting.google.c om...

Is it possible to write a structure to a file in c...as in c++...??
Yes.
is it using fwrite??



That''s what you''d use to write an exact binary
image, yes. Another way would be to write
a textual version, one member at a time.

-Mike


Mike Wahler wrote:

"Glen" <gl********@yahoo.co.in> wrote in message
news:eb**************************@posting.google.c om...

is it using fwrite??



That''s what you''d use to write an exact binary
image, yes. Another way would be to write
a textual version, one member at a time.



The second option would be better, because, AFAIK an exact binary image
may have problems with the size of the members of the structure, with
the alignment choosen by the compiler for the members of the structure
and even byte-endianness, if the output file is to be used across
different platforms.

I may be wrong, thought, and I would love to be corrected here if I am.

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Rogério Brito - rb****@ime.usp.br - http://www.ime.usp.br/~rbrito
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


这篇关于写一个结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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