64,678
社区成员
发帖
与我相关
我的任务
分享
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
string str;
unsigned char c; //BYTE类型,但是无法忽略图片文件中的类似(结束符)的某些像素点
char buf[3]; //缓冲区
ifstream fip;
fip.open("test.jpg", ios::in | ios::binary); //以二进制方式打开图片文件
while(fip.read((char*)(&c), sizeof(c)))//以二进制方式读取
{
sprintf(buf, "%X", c);//格式化输入,二进制读入并转换成十六进制字符(一个C库函数)
str += buf;
}
fip.close(); //关闭图片文件
cout << str << endl;
ofstream fop("test.txt");
fop << str;
fop.close();
return 0;
}
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ofstream fout("a.txt");
const int N=5;
int a[N]={6,1,8,3,5};
//排序
for(int i=0;i<N;i++)
{
for(int j=i+1;j<N;j++)
{
if(a[j]<a[i])
swap(a[j],a[i]);
}
}
for(int i=0;i<N;i++)
{
fout<<a[i]<<' ';
fout<<endl;
}
fout.close();
}