本文整理汇总了C++中std::ifstream::seekg方法的典型用法代码示例。如果您正苦于以下问题:C++ ifstream::seekg方法的具体用法?C++ ifstream::seekg怎么用?C++ ifstream::seekg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ifstream
的用法示例。
在下文中一共展示了ifstream::seekg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetBoardDimensionsFromFile
/**
*
* Determines what are the dimensions of a labyrinth stored in a file.
*
* \param [in] InputFile
* The file to read data from
*
* \param [out] RowsCount
* A variable which will receive the numbe of rows in the labyrinth.
* The variable will be altered only if the file contains valid data.
*
* \param [out] ColsCount
* A variable which will receive the numbe of columns in the labyrinth.
* The variable will be altered only if the file contains valid data.
*
* \return
* true if the file contains valid data and the dimensions were written
* to RowsCount and ColsCount. Otherwise the function returns false.
*
*/
bool Board::GetBoardDimensionsFromFile(std::ifstream & InputFile, int& RowsCount, int& ColsCount)
{
InputFile.clear();
InputFile.seekg(0, std::ios::beg);
int rows = 0; // Number of rows in the board
int cols = 0; // Number of columns in the board
char c = 0;
int counter = 0;
// Find the number of columns in the board
while (InputFile.get(c) && c != '\n')
cols++;
// Find the number of rows in the board and also
// verify that all rows have the same number of columns
if (cols > 0)
{
rows++; // at leas one row was read from the file
while (InputFile.get(c))
{
if (c == '\n')
{
// the number of columns on each line must be the same
if (cols != counter)
return false;
rows++;
counter = 0;
}
else
{
counter++;
}
}
// The last row of the labyrinth may or may not be followed by a blank line
// Thus if we just count the number of new lines, we may count one row less
if (c != '\n')
rows++;
}
RowsCount = rows;
ColsCount = cols;
return true;
}
示例2:
bool
inspect<RopeHeader>(std::ifstream& in, size_type&, size_type&)
{
in.seekg(0);
RopeHeader header;
header.load(in);
if(!(header.check())) {
return false;
}
in.close();
std::cout << header << std::endl;
return true;
}
示例3: readInt
int TransFunc1DKeys::openImageJBinary(std::ifstream& fileStream, bool raw) {
// the default quantity of colors
int numColors = 256;
if (!raw) {
// read the header information seperatly
int id = readInt(fileStream);
if (id != 1229147980) {
// a leading 1229147980 (= 'ICOL') indicates an NIH Image LUT
// if ICOL isn't the first entry in the table, let the other procedures handle it
// but first, go back to the beginning
fileStream.seekg(std::ios::beg);
return 0;
}
readShort(fileStream); // Version
numColors = readShort(fileStream); // Number of Colors
readShort(fileStream); // Start
readShort(fileStream); // End
readDouble(fileStream); // Filler1
readDouble(fileStream); // Filler2
readInt(fileStream); // Filler3
}
// The colors in a binary table are saved in succession so
// first load the reds, then greens and at last blues
char redColors[256];
char greenColors[256];
char blueColors[256];
try {
fileStream.read(&redColors[0], numColors);
fileStream.read(&greenColors[0], numColors);
fileStream.read(&blueColors[0], numColors);
}
catch (...) {
throw;
}
unsigned char data[256*4];
for (int i = 0; i < 256; ++i) {
data[i*4 + 0] = redColors[i];
data[i*4 + 1] = greenColors[i];
data[i*4 + 2] = blueColors[i];
data[i*4 + 3] = (char)(255);
}
dimensions_ = tgt::ivec3(256, 1, 1);
generateKeys(&data[0]);
return 256;
}
示例4:
void Q3BSPLoad::LoadLightmaps(std::ifstream& aFile)
{
//Calculate number of lightmaps
int num_lightmaps=m_header.m_directoryEntries[bspLightmaps].m_length/sizeof(BSP_LOAD_LIGHTMAP);
//Create space for this many BSP_LOAD_LIGHTMAPs
m_loadLightmaps.resize(num_lightmaps);
//Load textures
aFile.seekg(m_header.m_directoryEntries[bspLightmaps].m_offset,std::ios::beg);
aFile.read((char*)&m_loadLightmaps[0], m_header.m_directoryEntries[bspLightmaps].m_length);
//Change the gamma settings on the lightmaps (make them brighter)
float gamma=2.5f;
for(int i=0; i<num_lightmaps; ++i)
{
for(int j=0; j<128*128; ++j)
{
float r, g, b;
r=m_loadLightmaps[i].m_lightmapData[j*3+0];
g=m_loadLightmaps[i].m_lightmapData[j*3+1];
b=m_loadLightmaps[i].m_lightmapData[j*3+2];
r*=gamma/255.0f;
g*=gamma/255.0f;
b*=gamma/255.0f;
//find the value to scale back up
float scale=1.0f;
float temp;
if(r > 1.0f && (temp = (1.0f/r)) < scale) scale=temp;
if(g > 1.0f && (temp = (1.0f/g)) < scale) scale=temp;
if(b > 1.0f && (temp = (1.0f/b)) < scale) scale=temp;
// scale up color values
scale*=255.0f;
r*=scale;
g*=scale;
b*=scale;
//fill data back in
m_loadLightmaps[i].m_lightmapData[j*3+0]=(unsigned char)r;
m_loadLightmaps[i].m_lightmapData[j*3+1]=(unsigned char)g;
m_loadLightmaps[i].m_lightmapData[j*3+2]=(unsigned char)b;
//m_loadLightmaps[i].m_lightmapData[j*3+0]=(GLubyte)255;
//m_loadLightmaps[i].m_lightmapData[j*3+1]=(GLubyte)255;
//m_loadLightmaps[i].m_lightmapData[j*3+2]=(GLubyte)255;
}
}
}
示例5: readHeaders
/**
* Reads the headers of a region file: chunk offsets/timestamps
*/
bool RegionFile::readHeaders(std::ifstream& file) {
if (!file)
return false;
containing_chunks.clear();
for (int i = 0; i < 1024; i++) {
chunk_offsets[i] = 0;
chunk_timestamps[i] = 0;
}
for (int x = 0; x < 32; x++) {
for (int z = 0; z < 32; z++) {
file.seekg(4 * (x + z * 32), std::ios::beg);
int tmp;
file.read((char*) &tmp, 4);
if (tmp == 0)
continue;
int offset = be32toh(tmp << 8) * 4096;
//uint8_t sectors = ((uint8_t*) &tmp)[3];
file.seekg(4096, std::ios::cur);
int timestamp;
file.read((char*) ×tamp, 4);
timestamp = be32toh(timestamp);
ChunkPos pos(x + regionpos.x * 32, z + regionpos.z * 32);
if (rotation)
pos.rotate(rotation);
containing_chunks.insert(pos);
chunk_offsets[z * 32 + x] = offset;
chunk_timestamps[z * 32 + x] = timestamp;
}
}
return true;
}
示例6: fill_nt_structures
void fill_nt_structures(std::ifstream &file)
{
/* Remember where the caller was in the file */
std::streampos off = file.tellg();
file.seekg(imgDosHeader.e_lfanew, std::ios::beg);
file.read((char*)&imgNtHeaders, get_nt_headers_size());
file.seekg(imgDosHeader.e_lfanew, std::ios::beg);
/* This offset is relative to the NT Header, do not forget to move the file pointer on it */
file.seekg(imgNtHeaders.get_offset_first_section(), std::ios::cur);
for(unsigned int i = 0; i < imgNtHeaders.FileHeader.NumberOfSections; ++i)
{
RP_IMAGE_SECTION_HEADER* pImgSectionHeader = new (std::nothrow) RP_IMAGE_SECTION_HEADER;
if(pImgSectionHeader == NULL)
RAISE_EXCEPTION("Cannot allocate memory for pImgSectionHeader");
file.read((char*)pImgSectionHeader, get_image_section_header_size());
imgSectionHeaders.push_back(pImgSectionHeader);
}
file.seekg(off);
}
示例7: LxaEndException
/**
* get the data at the ith position
* throws out of file exception
*/
LaserxaData
get_data (size_t i)
{
if (i >= data_count_)
{
throw LxaEndException ();
}
const size_t pos = sizeof(LaserxaInfo) + i * sizeof(LaserxaData);
LaserxaData d;
file_in_.seekg (pos, std::ios::beg);
file_in_.read ((char*) &d, sizeof(LaserxaData));
return d;
}
示例8: sizeof
//! TODO
static void
_read_variable_length_records(std::ifstream &ifs,
const public_header_block &phb,
std::vector<variable_length_record> *vlr)
{
if (0 != vlr) {
}
else { // Skip past VLR data.
ifs.seekg(
phb.offset_to_data -
sizeof(public_header_block) -
sizeof(uint16),
std::ios_base::cur);
}
}
示例9: getLastLine
std::string getLastLine(std::ifstream& in)
{
std::ifstream::pos_type pos = in.tellg();
std::ifstream::pos_type lastPos;
while (in >> std::ws && ignoreline(in, lastPos))
pos = lastPos;
in.clear();
in.seekg(pos);
std::string line;
std::getline(in, line);
return line;
}
示例10: sizeof
bool WLMatLib::MATReader::readTagField( mDataType_t* const dataType, mNumBytes_t* const numBytes, std::ifstream& ifs )
{
const std::streampos pos = ifs.tellg();
ifs.read( ( char* )dataType, sizeof(WLMatLib::mDataType_t) );
ifs.read( ( char* )numBytes, sizeof(WLMatLib::mNumBytes_t) );
if( *dataType > WLMatLib::DataTypes::miUTF32 )
{
wlog::debug( LIBNAME ) << "Small Data Element Format found.";
WLMatLib::mDataTypeSmall_t typeSmall;
WLMatLib::mNumBytesSmall_t bytesSmall;
ifs.seekg( -( sizeof(WLMatLib::mDataType_t) + sizeof(WLMatLib::mNumBytes_t) ), ifstream::cur );
ifs.read( ( char* )&typeSmall, sizeof(WLMatLib::mDataTypeSmall_t) );
ifs.read( ( char* )&bytesSmall, sizeof(WLMatLib::mNumBytesSmall_t) );
*dataType = typeSmall;
*numBytes = bytesSmall;
}
if( *dataType > WLMatLib::DataTypes::miUTF32 )
{
wlog::error( LIBNAME ) << "Unknown data type or wrong data structure!";
ifs.seekg( pos );
return false;
}
return true;
}
示例11: Copier
Copier(CopyDescriptor desc,
unsigned block_size)
: _desc(desc),
_src(_desc.src.c_str()),
_dest(_desc.dest.c_str()),
_block_size(block_size)
{
_done = false;
// get length of the source file
_src.seekg (0, std::ios::end);
_src_length = _src.tellg();
_src.seekg (0, std::ios::beg);
_src_offset = 0;
if(_src_length == 0)
_done = true;
if(!_src.good())
throw "Unable to open source file!";
if(!_dest.good())
throw "Unable to open dest file!";
}
示例12: make_pair
inline std::pair<uint32_t, uint32_t> lookup3(std::ifstream &stream, uint32_t length, const std::pair<uint32_t, uint32_t> &init = { 0, 0 })
{
auto pc = init.first;
auto pb = init.second;
std::vector<char> buffer(length);
auto pos = stream.tellg();
stream.read(buffer.data(), length);
hashlittle2(buffer.data(), length, &pc, &pb);
stream.seekg(pos);
return std::make_pair(pc, pb);
}
示例13: FindChunk
bool FindChunk(std::ifstream& stream, DWORD fourcc, DWORD& dwChunkSize, DWORD& dwChunkDataPosition){
stream.seekg(0, std::ios::beg);
DWORD dwChunkType(0), dwChunkDataSize(0), dwRIFFDataSize(0), dwFileType(0), dwOffset(0);
while(!stream.eof()){// as long as we have not hit the end of the file
// riff standard is always type, followied by the chunk size. They are always 4 bytes too,
stream.read(reinterpret_cast<char*>(&dwChunkType), 4);
stream.read(reinterpret_cast<char*>(&dwChunkDataSize), 4);
if( fourccRIFF ==dwChunkType){// at the riff header
dwRIFFDataSize = dwChunkDataSize;
dwChunkDataSize = 4;
stream.read(reinterpret_cast<char*>(&dwFileType), 4);
} else stream.seekg(dwChunkDataSize, std::ios::cur);// skip this chunk
dwOffset += sizeof(DWORD) * 2;
if (dwChunkType == fourcc){// found what we were looking for
dwChunkSize = dwChunkDataSize;
dwChunkDataPosition = dwOffset;
return true;
}
dwOffset += dwChunkDataSize;
}
char* temp = reinterpret_cast<char*>(&fourcc);
OUTPUT_DEBUG_MSG("Could not find the chunk "<<temp[0]<<temp[1]<<temp[2]<<temp[3]);
return false;// if this is hit, it means what we were searching for was not found
}
示例14: hasXerror
/**
* Checks if there is an x error present in the data set
* @param stream:: the stream object
*/
bool LoadRKH::hasXerror(std::ifstream &stream) {
auto containsXerror = false;
auto currentPutLocation = stream.tellg();
std::string line;
getline(stream, line);
std::string x, y, yerr, xerr;
std::istringstream datastr(line);
datastr >> x >> y >> yerr >> xerr;
if (!xerr.empty()) {
containsXerror = true;
}
// Reset the original location of the stream
stream.seekg(currentPutLocation, stream.beg);
return containsXerror;
}
示例15: LoadTexCoords
void LoadTexCoords(std::vector<Vec2f>& uv, std::ifstream& f, unsigned int) {
f.clear(std::ios_base::goodbit);
f.seekg(0, std::ios_base::beg);
while (!f.eof()) {
char buf[1024] = { 0 };
char buf1[64] = { 0 };
f.getline(buf, 1024);
sscanf(buf, "%s", buf1);
if (strcmp(buf1, "vt") == 0) {
uv.resize(uv.size() + 1);
LoadTexCoord(uv.back(), buf + 3);
}
}
}