当前位置: 首页>>代码示例>>C++>>正文


C++ fstream::seekg方法代码示例

本文整理汇总了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;
}
开发者ID:Yashchuk,项目名称:GL-Base-camp,代码行数:33,代码来源:XorEncryptor.cpp

示例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;
}
开发者ID:Phrohdoh,项目名称:ccmix,代码行数:28,代码来源:mix_header.cpp

示例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;
	}
开发者ID:somaen,项目名称:Wintermute-git,代码行数:13,代码来源:myfilestream.cpp

示例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;
}
开发者ID:TanninOne,项目名称:modorganizer-bsatk,代码行数:25,代码来源:bsafolder.cpp

示例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) {
开发者ID:Hsaniva,项目名称:apitrace,代码行数:26,代码来源:trace_file_snappy.cpp

示例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;
}
开发者ID:dongxu-cug,项目名称:gimli,代码行数:7,代码来源:gimli.cpp

示例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;
}
开发者ID:AmarSaggu,项目名称:ORAM,代码行数:8,代码来源:File.cpp

示例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;
	}
开发者ID:CBaiz,项目名称:PeLib,代码行数:8,代码来源:PeLibAux.cpp

示例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;
}
开发者ID:shengyang998,项目名称:Libarary-system,代码行数:10,代码来源:user.cpp

示例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);
		}
	}
开发者ID:somaen,项目名称:grime-tools-mac,代码行数:11,代码来源:filestream.cpp

示例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);
}
开发者ID:campisano,项目名称:b_plus_tree,代码行数:12,代码来源:IndexDataStructure.cpp

示例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;
		}
	}
开发者ID:somaen,项目名称:grime-tools-mac,代码行数:14,代码来源:filestream.cpp

示例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;
 }
开发者ID:webary,项目名称:SocketChatRoom,代码行数:14,代码来源:CXXFStream.hpp

示例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;
	}
开发者ID:somaen,项目名称:Wintermute-git,代码行数:30,代码来源:myfilestream.cpp

示例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;

}
开发者ID:Rajatkosh,项目名称:IDTESRC,代码行数:25,代码来源:ID3V2_Header.cpp


注:本文中的std::fstream::seekg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。