试图将文件的一部分读入向量结构。 特别是尝试使用标准库读取 exif 数据。 此代码编译但向量(“缓冲区”)是空的。
已经为此工作了几天。学习C++。对 PHP 更有经验。我知道 - 我可能应该研究一些基础知识而不是这个,但这更有趣。任何帮助将不胜感激。
void File_iterate ( const std::string* Filename ) {
std::ifstream infile ( *Filename, std::ios::binary );
if ( !infile ) { std::cout << "Error: file unavailable\n"; exit(1); }
infile.seekg( 0xE1, std::ios::beg ); // Seek to the position of the 0xE1 tag
long CopyFrom = infile.tellg();
unsigned short length;
infile.read(reinterpret_cast<char*>(&length), sizeof(length) ); // Read the two bytes following the 0xE1 tag to obtain the length of the exifData
infile.seekg( 0, std::ios::end );
std::cout << "Length of exifData: " << length << " bytes.\n";
std::cout << "Size of file: " << infile.tellg() << " bytes\n";
long CopyTo = CopyFrom + length;
std::cout << "Exif Position: " << CopyFrom << " - " << CopyTo << "\n";
std::vector<uint8_t> buffer;
buffer.reserve(length);
infile.seekg( 0xE1, std::ios::beg ); // Reset input stream
infile.read( (char*)buffer.data() , length); // <-- THIS DOES NOT WORK :(
std::cout << "Length of buffer: " << buffer.size() << " bytes\n" ;
infile.close();
for ( int i : buffer ) {
if ( buffer[i] == 0xE1 ) { std::cout << buffer[i]; }
if ( buffer[i] == 0x9003 ) { std::cout << buffer[i]; }
}