C++ピクチャ暗記(画像終了フラグ後にデータを加える)
2389 ワード
jpg画像開始フラグ:FFD 8終了フラグ:FFD 9
#include
#include
using namespace std;
class picture{
private:
ifstream ifile_picture;
ifstream ifile_txt;
ofstream ofile_picture;
ofstream ofile_txt;
int length_ifile_picture,length_ifile_txt;
char name_ifile_picture[50], name_ifile_txt[50], name_ofile_picture[50],name_ofile_txt[50];
public:
void Open(ifstream &ifile,char *name,int &length);
void M();
void m();
};
void picture::Open(ifstream &ifile,char *name,int &length)
{
ifile.open(name,ios::binary|ios::in);
if (!ifile)
{
cout<>this->name_ifile_picture;
Open(this->ifile_picture , this->name_ifile_picture , this->length_ifile_picture);
str = new char[length_ifile_picture + 5];
this->ifile_picture.read(str , this->length_ifile_picture);
while(1)
{
if(str[this->length_ifile_picture-2]==-1 && str[this->length_ifile_picture-1]==-39)break; // FF D9
else this->length_ifile_picture--;
}
cout<>this->name_ofile_picture;
this->ofile_picture.open(this->name_ofile_picture,ios::binary|ios::out);
if (!this->ofile_picture)
{
cout<name_ofile_picture<ofile_picture.write(str , this->length_ifile_picture);
this->ifile_picture.close();
delete []str;
cout<>this->name_ifile_txt;
Open(this->ifile_txt , this->name_ifile_txt , this->length_ifile_txt);
str = new char[length_ifile_txt + 5];
this->ifile_txt.read(str , this->length_ifile_txt);
this->ofile_picture.write(str , this->length_ifile_txt);
this->ifile_txt.close();
this->ofile_picture.close();
delete []str;
cout<>this->name_ifile_picture;
Open(this->ifile_picture , this->name_ifile_picture , this->length_ifile_picture);
str = new char[length_ifile_picture + 5];
this->ifile_picture.read(str , this->length_ifile_picture);
int l=this->length_ifile_picture;
while(1)
{
if(str[l-2]==-1 && str[l-1] == -39)break; // FF D9
else l--;
}
cout<>this->name_ofile_txt;
this->ofile_txt.open(this->name_ofile_txt,ios::binary|ios::out);
if (!this->ofile_picture)
{
cout<name_ofile_txt<ofile_txt.write(str+l , this->length_ifile_picture-l);
this->ifile_picture.close();
this->ofile_txt.close();
delete []str;
cout<