本文整理汇总了C++中std::fstream::seekg方法的典型用法代码示例。如果您正苦于以下问题:C++ fstream::seekg方法的具体用法?C++ fstream::seekg怎么用?C++ fstream::seekg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::fstream
的用法示例。
在下文中一共展示了fstream::seekg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: encryptData
bool XorEncryptor::encryptData(std::fstream &original, std::fstream &result)
{
if (!original.is_open() || !result.is_open())
{
return false;
}
original.seekg(0, std::ios::beg);
result.seekp(0, std::ios::beg);
char c = 0;
unsigned i = 0;
while (original.good())
{
original.read(&c, 1);
c ^= password[i];
if(original.gcount() > 0)
{
result.write(&c, 1);
}
if (++i == passSize)
{
i = 0;
}
}
original.seekg(0, std::ios::beg);
result.seekg(0, std::ios::beg);
result.flush();
return true;
}
示例2: readUnEncrypted
bool MixHeader::readUnEncrypted(std::fstream &fh)
{
t_mix_entry entry;
std::pair<t_mix_index_iter,bool> rv;
//new format won't have filecount yet
if(m_file_count) {
fh.seekg(6, std::ios::beg);
} else {
fh.seekg(4, std::ios::beg);
fh.read(reinterpret_cast<char*>(&m_file_count), sizeof(uint16_t));
fh.read(reinterpret_cast<char*>(&m_body_size), sizeof(uint32_t));
}
m_header_size += m_file_count * 12;
//read entries
for (uint16_t i = 0; i < m_file_count; i++) {
fh.read(reinterpret_cast<char*>(&entry.first), sizeof(int32_t));
fh.read(reinterpret_cast<char*>(&entry.second), sizeof(t_index_info));
rv = m_index.insert(entry);
if(!rv.second) {
std::cout << "Error reading header, duplicate ID" << std::endl;
return false;
}
}
return true;
}
示例3: size
/**
* Obtains the total size of the stream, measured in bytes.
* If this value is unknown or can not be computed, -1 is returned.
*
* @return the size of the stream, or -1 if an error occurred
*/
virtual int32 size() const {
int32 curPos = pos();
_stream->seekg(0, std::ios::end);
int32 curSize = pos();
_stream->seekg(curPos, std::ios::end);
return curSize;
}
示例4: readFolder
Folder::Ptr Folder::readFolder(std::fstream &file, BSAULong fileNamesLength,
BSAULong &endPos)
{
Folder::Ptr result(new Folder());
result->m_NameHash = readType<BSAHash>(file);
result->m_FileCount = readType<unsigned long>(file);
result->m_Offset = readType<unsigned long>(file);
std::streamoff pos = file.tellg();
file.seekg(result->m_Offset - fileNamesLength, fstream::beg);
result->m_Name = readBString(file);
for (unsigned long i = 0UL; i < result->m_FileCount; ++i) {
result->m_Files.push_back(File::Ptr(new File(file, result.get())));
}
if (static_cast<unsigned long>(file.tellg()) > endPos) {
endPos = static_cast<BSAULong>(file.tellg());
}
file.seekg(pos);
return result;
}
示例5: rawOpen
bool SnappyFile::rawOpen(const std::string &filename, File::Mode mode)
{
std::ios_base::openmode fmode = std::fstream::binary;
if (mode == File::Write) {
fmode |= (std::fstream::out | std::fstream::trunc);
createCache(SNAPPY_CHUNK_SIZE);
} else if (mode == File::Read) {
fmode |= std::fstream::in;
}
m_stream.open(filename.c_str(), fmode);
//read in the initial buffer if we're reading
if (m_stream.is_open() && mode == File::Read) {
m_stream.seekg(0, std::ios::end);
m_endPos = m_stream.tellg();
m_stream.seekg(0, std::ios::beg);
// read the snappy file identifier
unsigned char byte1, byte2;
m_stream >> byte1;
m_stream >> byte2;
assert(byte1 == SNAPPY_BYTE1 && byte2 == SNAPPY_BYTE2);
flushReadCache();
} else if (m_stream.is_open() && mode == File::Write) {
示例6: fileLength
uint fileLength(std::fstream & file){
std::streamoff oldPos = file.tellg();
file.seekg(0, std::ios::end);
std::streamoff length = file.tellg();
file.seekg(oldPos);
return (uint)length;
}
示例7: GetLength
size_t File::GetLength(std::fstream &file)
{
file.seekg(0, file.end);
size_t len = file.tellg();
file.seekg(0, file.beg);
return len;
}
示例8: fileSize
unsigned int fileSize(std::fstream& file)
{
unsigned int oldpos = file.tellg();
file.seekg(0, std::ios::end);
unsigned int filesize = file.tellg();
file.seekg(oldpos, std::ios::beg);
return filesize;
}
示例9: readUNPW
int User::readUNPW(std::fstream &fin){
auto fpos = fin.cur;
fin.seekg(0, fin.beg);
fin.read(username, sizeof(str));
fin.read(password, sizeof(str));
decode(username);
decode(password);
fin.seekg(fpos);
return 0;
}
示例10:
SeekableFileStream(const char *name) {
_fileStream = new std::fstream();
_fileStream->open(name, std::fstream::in | std::fstream::binary);
if (_fileStream->fail()) {
_length = -1;
} else {
_fileStream->seekg(0, std::ios_base::end);
_length = _fileStream->tellg();
_fileStream->seekg(0, std::ios_base::beg);
}
}
示例11: loadAt
void IndexDataStructure::loadAt(std::fstream & _input_file, std::streampos _position)
{
// remember the read file position
std::streampos r_pos = _input_file.tellg();
// go to asked read position
_input_file.seekg(_position);
readToNext(_input_file);
// restore original read position
_input_file.seekg(r_pos);
}
示例12: seek
virtual bool seek(int32 offset, int whence = SEEK_SET) {
_fileStream->clear();
switch (whence) {
case SEEK_SET:
_fileStream->seekg(offset, std::ios_base::beg);
break;
case SEEK_CUR:
_fileStream->seekg(offset, std::ios_base::cur);
break;
case SEEK_END:
_fileStream->seekg(offset, std::ios_base::end);
break;
}
}
示例13: CXXFStream
CXXFStream(const char* _name,std::ios_base::openmode _mode):file(_name,_mode| std::ios::binary) {
if(!file) {
size = 0;
return;
}
file.seekg(0, std::ios::end);
size = (long)file.tellg();
file.seekg(0, std::ios::beg);//将指针重新定位到文件开头
int i;
for(i=0; i<10; ++i) //0~9
ox2d[i] = i;
for(i=49; i<55; ++i) //a~f、A~F
ox2d[i] = ox2d[i-32] = i-39;
}
示例14: seek
/**
* Sets the stream position indicator for the stream. The new position,
* measured in bytes, is obtained by adding offset bytes to the position
* specified by whence. If whence is set to SEEK_SET, SEEK_CUR, or
* SEEK_END, the offset is relative to the start of the file, the current
* position indicator, or end-of-file, respectively. A successful call
* to the seek() method clears the end-of-file indicator for the stream.
*
* @note The semantics of any implementation of this method are
* supposed to match those of ISO C fseek().
*
* @param offset the relative offset in bytes
* @param whence the seek reference: SEEK_SET, SEEK_CUR, or SEEK_END
* @return true on success, false in case of a failure
*/
virtual bool seek(int32 offset, int whence = SEEK_SET) {
if (whence == SEEK_SET) {
_stream->seekg(offset, std::ios::beg);
} else if (whence == SEEK_CUR) {
_stream->seekg(offset, std::ios::cur);
} else {
_stream->seekg(offset, std::ios::end);
}
if (_stream->fail())
return false;
if (_stream->bad())
return false;
return true;
}
示例15: Bytes
void ID3V2_Header::Get_Header(std::fstream& file)
{
file.seekg(0); //Sets The Pointer To Points At The Begining Of The File
//Let's Get The Below Process According To The ID3v2 Standrad
file.read((char*)Header_id ,3); // Read 3 Bytes in Header i.e. "I" "D" "3"
file.read((char*)&Version,1); // Reads The Next 1 byte actually 8-bits i.e. ID3 Version in The Version Member
file.read((char*)&Revision,1); // Reads Next 1 Byte actually 8-bits i.e. ID3 Revision No. in The Revision Member
file.read((char*)&Header_flags,1); // Reads Header Flags
unsigned char memory[4];
file.read((char*)memory,sizeof(Header_size)); //Reads 4 Bytes (Sync Safe Form) in Memory.
Header_size = (memory[3] & 0xFF) | //Finally Desynchronise The Synch. Safe Integer i.e.0xxxxxxx 0xxxxxxx ......
((memory[2] & 0xFF) << 7 ) | // Size = 0xxxxxxx
((memory[1] & 0xFF) << 14 ) | // + 0xxxxxxx
((memory[0] & 0xFF) << 21 ); // + 0xxxxxxx
// + 0xxxxxxx
//__________________________________________
// Size = xxxxxxxxxxxxxxxxxxxxxxxxxxxx where + = OR Operation
if ((Header_id[0]=='I')and(Header_id[1]=='D')and(Header_id[2]=='3')) // Checks If Header ID is I D 3
Is_present = 1;
else
Is_present = 0;
}