所需代码的描述 [英] Description of a code needed

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

问题描述

我不知道此代码的粗体含义,请提供帮助.我确实了解文件处理,但不了解sizeof()函数等.请帮忙!

I Don''t know the meaning of this code in bold, please help. I do know about the file handling but not about the sizeof() function etc. please help!

void function()
{ofstream o;
	char ch;
o.open("abc.txt",ios::out|ios::app);
	do
	{
		system ("cls");
		bk.create_book();   //create_book is a function in the class by the name of "book"//
		o.write((char*)&bk,sizeof(book));     //bk is an object of the class "book"//
		cout<<"\n\nDo you want to add more record..(y/n?)";
		cin>>ch;
	}while(ch=='y'||ch=='Y');
	o.close();
}

推荐答案

简短的答案是您不应该在C ++中执行的操作,除非您真的知道自己在做什么,甚至在那里通常是更好的方法.

长答案是将包含bk的内存块写入文件"abc.txt".希望这不是您要使用记事本进行编辑的内容,因为肯定会在其中写入大量旧垃圾后,地狱不会成为文本文件.

干杯,



PS:真的,不要这样做...

PPS:不,除非您要删除大量的代码,否则请别动手.
The short answer is something you shouldn''t do in C++ unless you really know what you''re doing, and even then there''s usually a better way.

The long answer is that it''s writing the block of memory containing bk to the file "abc.txt." Which hopefully isn''t something you''re going to want to edit with notepad as it sure as hell won''t be a text file after a lump of any old rubbish gets written in there.

Cheers,

Ash

PS: Really, don''t do it...

PPS: No, take your hands away from the keyboard unless you''re going to delete that lump of code...


粗体字是在进行穷人"序列化. sizeof运算符已(令人惊讶地!)记录在案,例如,参见 ^ ].
The bold line is doing ''poor-man'' serialization. the sizeof operator is (surprisingly!) documented, see, for instance MSDN[^].


sizeof()运算符返回您作为参数传递的对象的字节大小.
sizeof() operator returns the size in bytes of the object you pass as a parameter.


这篇关于所需代码的描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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