本文整理汇总了C++中std::fstream::tellg方法的典型用法代码示例。如果您正苦于以下问题:C++ fstream::tellg方法的具体用法?C++ fstream::tellg怎么用?C++ fstream::tellg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::fstream
的用法示例。
在下文中一共展示了fstream::tellg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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) {
示例5: 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;
}
示例6: ReadOtherInfoFromFile
UINT64 TargetPhrase::ReadOtherInfoFromFile(UINT64 filePos, std::fstream &fileTPColl)
{
CHECK(filePos == (UINT64)fileTPColl.tellg());
UINT64 memUsed = 0;
fileTPColl.read((char*) &m_filePos, sizeof(UINT64));
memUsed += sizeof(UINT64);
CHECK(m_filePos != 0);
memUsed += ReadAlignFromFile(fileTPColl);
CHECK((memUsed + filePos) == (UINT64)fileTPColl.tellg());
memUsed += ReadScoresFromFile(fileTPColl);
CHECK((memUsed + filePos) == (UINT64)fileTPColl.tellg());
return memUsed;
}
示例7: Read
bool OsFileImpl::Read( void* Data, size_t Size )
{
if( !IsValid() )
{
return false;
}
mFile.read( ( char* )Data, Size );
mPosition = mFile.tellg();
return IsValid();
}
示例8: GetContents
String File::GetContents(std::fstream & fileStream)
{
assert(fileStream.is_open());
fileStream.seekg( 0, std::ios::beg);
int start = (int) fileStream.tellg();
fileStream.seekg( 0, std::ios::end );
int fileSize = (int) fileStream.tellg();
// Empty file?
if (fileSize == 0)
return String();
assert(fileSize);
char * data = new char [fileSize+2];
memset(data, 0, fileSize+1);
fileStream.seekg( 0, std::ios::beg);
fileStream.read((char*) data, fileSize);
String strData(data);
delete[] data;
return strData;
}
示例9: copyUntilEOFInString
/*!
* Copies entire file into a char array
* @param[in] str file stream to be copied; file nneds already to be opened
* @param[out] buffer char array containing entire array
* @param[out] length number of elements which hvae benn copied
*/
void copyUntilEOFInString( std::fstream &str, char*& buffer, int &length) {
std::fstream::pos_type position_insert, position_eof ;
position_insert = str.tellg() ;
str.seekg(0, str.end);
position_eof = str.tellg();
length = position_eof - position_insert ;
buffer = new char[length] ;
str.seekg(position_insert);
str.read(buffer,length ) ;
str.seekg(position_insert);
return;
};
示例10: readBlockFromFile
Block readBlockFromFile(std::fstream& f) {
Block b {};
BlockOffset off = f.tellg();
f.read(reinterpret_cast<char *>(&b.data), sizeof(b.data));
for(auto& o : b.offsets) {
f.read(reinterpret_cast<char *>(&o), sizeof(o));
}
f.seekg(off, f.beg);
return b;
}
示例11: Write
bool OsFileImpl::Write( void const* Src, size_t Size )
{
if( !IsValid() )
{
return false;
}
mSize += Size;
mFile.write( ( char const* )Src, Size );
mPosition = mFile.tellg();
return IsValid();
}
示例12:
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);
}
}
示例13: 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);
}
示例14: ChunkWrite
void MeshFileLoader::ChunkWrite( std::fstream &filestr, char *src, unsigned size, unsigned chunksize )
{
if (!size)
return;
int filesize = (int)filestr.tellg();
int chunks = size / chunksize;
for ( int i = 0; i < chunks; ++i )
{
filestr.write( src + i * chunksize, chunksize );
}
filestr.write( src + chunks * chunksize, size % chunksize );
}
示例15: readToNext
void IndexDataStructure::readToNext(std::fstream & _input_file)
{
m_is_indexed = true;
m_index_position = _input_file.tellg();
_input_file.read((char *)(&m_count), sizeof(m_count));
_input_file.read((char *)(m_keys), sizeof(m_keys[0]) * m_max_count);
_input_file.read((char *)(m_addresses), sizeof(m_addresses[0]) * m_max_count);
_input_file.read((char *)(&m_next_sibling_address), sizeof(m_next_sibling_address));
// skip free block space
_input_file.seekg(m_block_size - m_real_data_size, _input_file.cur);
}