/*
* File: main.cpp
* Author: hcx
*
* Created on July 3, 2013, 4:04 PM
*/
#include <cstdlib>
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/positioning.hpp>
#include <cstring>
#include <iostream>
using boost::iostreams::file_sink;
using boost::iostreams::file_source;
using boost::iostreams::position_to_offset;
using boost::iostreams::seek;
using boost::iostreams::stream_offset;
using namespace std;
/*
* JPG 文件结尾的两个字节是 ff 0d。
*/
int main(int argc, char** argv) {
char buf[3];
memset(buf, '\0', sizeof buf);
file_source in("/home/hcx/pic/camera-vehicle/1g2pf413.4dk.slice.jpg", BOOST_IOS::binary);
//------返回一个 stream_offset 表示与 pos 同一个字符位置,忽略任何代码转换状态。----------------//
stream_offset off;
off = position_to_offset(seek(in, -2, BOOST_IOS::end));
//------------------------------//
streamsize nr = in.read(buf, 2);
short end0=(short)buf[0];
short end1=(short)buf[1];
if(end0==-1 && end1==-39)
cout<<"This image is an jpg picture."<<endl;
else
cout<<"This image is not an jpg picture."<<endl;
return 0;
}
* File: main.cpp
* Author: hcx
*
* Created on July 3, 2013, 4:04 PM
*/
#include <cstdlib>
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/positioning.hpp>
#include <cstring>
#include <iostream>
using boost::iostreams::file_sink;
using boost::iostreams::file_source;
using boost::iostreams::position_to_offset;
using boost::iostreams::seek;
using boost::iostreams::stream_offset;
using namespace std;
/*
* JPG 文件结尾的两个字节是 ff 0d。
*/
int main(int argc, char** argv) {
char buf[3];
memset(buf, '\0', sizeof buf);
file_source in("/home/hcx/pic/camera-vehicle/1g2pf413.4dk.slice.jpg", BOOST_IOS::binary);
//------返回一个 stream_offset 表示与 pos 同一个字符位置,忽略任何代码转换状态。----------------//
stream_offset off;
off = position_to_offset(seek(in, -2, BOOST_IOS::end));
//------------------------------//
streamsize nr = in.read(buf, 2);
short end0=(short)buf[0];
short end1=(short)buf[1];
if(end0==-1 && end1==-39)
cout<<"This image is an jpg picture."<<endl;
else
cout<<"This image is not an jpg picture."<<endl;
return 0;
}