如何在文件前面插入两个字节 [英] how to insert tow byte in front of a file

查看:107
本文介绍了如何在文件前面插入两个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(大家好...... ^ _ ^)


我尝试了这些方式:


fstream riape​​rto(" codici。 dat",ios :: out | ios :: binary | ios :: app);

if(riape​​rto.bad()){

cerr<<"" errore di apertura"<< endl;

system(" Pause");

}


riape​​rto.seekp (ios :: beg);

riape​​rto.put(char(nbyte / 256));

riape​​rto.put(char(nbyte%256));


^ =这个字节写在文件的末尾(好吧,它是

" app")。


ofstream riape​​rto(" codici.dat",ios :: out | ios :: binary);

if(riape​​rto.bad()){

cerr<<"&#errore di apertura"<< endl;

system(" Pause");

}

riape​​rto.seekp(ios :: beg);

riape​​rto.put(char(nbyte / 256));

riape​​rto.put(char(nbyte) %256));


它在开头写的这个,但是,文件包含o nly那个

两个字节......(覆盖)


我该怎么办?


提前致谢..


Gnafu

(Hi to all... ^_^)

I tryed theese ways:

fstream riaperto( "codici.dat", ios::out|ios::binary|ios::app);
if(riaperto.bad()){
cerr<<"errore di apertura"<<endl;
system("Pause");
}

riaperto.seekp(ios::beg);
riaperto.put(char(nbyte/256));
riaperto.put(char(nbyte%256));

^= This one writes the bytes at the end of the file (allright, it''s the
"app") .

ofstream riaperto( "codici.dat", ios::out|ios::binary);
if(riaperto.bad()){
cerr<<"errore di apertura"<<endl;
system("Pause");
}

riaperto.seekp(ios::beg);
riaperto.put(char(nbyte/256));
riaperto.put(char(nbyte%256));

This one it writes at the beginning but, then, the file contains only that
tow bytes... (overwrite)

What can i do?

Thanks in advance..

Gnafu


推荐答案

Gnafu写道:
Gnafu wrote:
(大家好...... ^ _ ^)

我尝试了这些方式:

fstream riape​​rto(" codici.dat" ,ios :: out | ios :: binary | ios :: app);
if(riape​​rto.bad()){
cerr<<" errore di apertura"<< endl;
系统(暂停);
}

riape​​rto.seekp(ios :: beg);
riape​​rto.put(char(nbyte / 256)) ; riape​​rto.put(char(nbyte%256));

^ =这个字节写在文件的末尾(好吧,它是
app)。

ofstream riape​​rto(" codici.dat",ios :: out | ios :: binary);
if(riape​​rto.bad()){
cerr&l t;<" errore di apertura"<< endl;
system(" Pause");


riape​​rto.seekp(ios :: beg) ;
riape​​rto.put(char(nbyte / 256));
riape​​rto.put(char(nbyte%256));

这是它在开头写的那个,但是,那么,该文件只包含
那两个字节...(覆盖)

我该怎么办?

提前致谢..
(Hi to all... ^_^)

I tryed theese ways:

fstream riaperto( "codici.dat", ios::out|ios::binary|ios::app);
if(riaperto.bad()){
cerr<<"errore di apertura"<<endl;
system("Pause");
}

riaperto.seekp(ios::beg);
riaperto.put(char(nbyte/256));
riaperto.put(char(nbyte%256));

^= This one writes the bytes at the end of the file (allright, it''s the
"app") .

ofstream riaperto( "codici.dat", ios::out|ios::binary);
if(riaperto.bad()){
cerr<<"errore di apertura"<<endl;
system("Pause");
}

riaperto.seekp(ios::beg);
riaperto.put(char(nbyte/256));
riaperto.put(char(nbyte%256));

This one it writes at the beginning but, then, the file contains only
that
tow bytes... (overwrite)

What can i do?

Thanks in advance..




将您想要的新字节写入临时文件,然后复制原始文件的内容

。如果成功,请将临时文件

重命名为原始名称。



Write the new bytes you want to a temporary file, then copy the content of
the original file over. If that was successful, rename the temporary file
to the name of the original.


文章< e7 ** ***********@news.t-online.com>,
ra ** **** @ t-online.de 说...


[...]
In article <e7*************@news.t-online.com>,
ra******@t-online.de says...

[ ... ]
写新的你想要一个临时文件的字节,然后复制原始文件的内容。如果成功,请将临时文件重命名为原始名称。
Write the new bytes you want to a temporary file, then copy the content of
the original file over. If that was successful, rename the temporary file
to the name of the original.




....并希望没有其他硬链接文件 -

因为如果有,你现在有两个单独的文件,

和所有其他硬链接指向未经修改的

文件。


-

后来,

杰瑞。


宇宙是一个自己想象的虚构。



....and hope there are no other hard links to the file --
because if there are, you now have two separate files,
and all of the other hard links point to the unmodified
file.

--
Later,
Jerry.

The universe is a figment of its own imagination.


>将您想要的新字节写入临时文件,然后复制原始文件的
> Write the new bytes you want to a temporary file, then copy the content of
的内容。如果成功,请将临时文件重命名为原始名称。
the original file over. If that was successful, rename the temporary file
to the name of the original.




我不想这样做.... :(

好​​的,不管怎样,谢谢..



I wanted to not do that.... :(
Ok, thank anyway..


这篇关于如何在文件前面插入两个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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