65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string in="E:\\mona_lisa.jpg";
string out="E:\\m.jpg";
ifstream infile;
ofstream outfile;
infile.open(in.c_str());
outfile.open(out.c_str());
if(!infile||!outfile)
{
cerr<<"error in IO!"<<endl;
return -1;
}
unsigned int point;
point=1;
while(infile>>point)
{
cout<<point<<" ";
}
cout<<hex<<point<<" ";
infile.close();
outfile.close();
return 0;
}
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string in="a.jpg";
string out="m.jpg";
ifstream infile;
ofstream outfile;
infile.open(in.c_str());
outfile.open(out.c_str());
if(!infile||!outfile)
{
cerr<<"error in IO!"<<endl;
return -1;
}
//unsigned int point;//delete this line
//point=1; // delete this line
char point; // add this line;
while(infile>>point)
{
cout<<point<<" ";
}
cout<<hex<<point<<" ";
infile.close();
outfile.close();
return 0;
}
试试:(最好把in,out的变量也改一下)
infile.open(in1.c_str(),ios_base::binary|ios_base::in);
outfile.open(out1.c_str(),ios_base::binary|ios_base::out);
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string in="a.jpg";
string out="m.jpg";
ifstream infile;
ofstream outfile;
infile.open(in.c_str());
outfile.open(out.c_str());
if(!infile||!outfile)
{
cerr<<"error in IO!"<<endl;
return -1;
}
//unsigned int point;//delete this line
//point=1; // delete this line
char point; // add this line;
while(infile>>point)
{
cout<<"a";
}
cout<<hex<<point<<" ";
infile.close();
outfile.close();
return 0;
}