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


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

本文整理汇总了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;
}
开发者ID:slavi91,项目名称:sdp-samples,代码行数:70,代码来源:Board.cpp

示例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;
}
开发者ID:jltsiren,项目名称:bwt-merge,代码行数:14,代码来源:bwt_inspect.cpp

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

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

示例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*) &timestamp, 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;
}
开发者ID:ExerciseBook,项目名称:MCImporter,代码行数:40,代码来源:region.cpp

示例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);
    }
开发者ID:navtej,项目名称:rp,代码行数:24,代码来源:pe_struct.hpp

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

    }
开发者ID:tlatzko,项目名称:gloc,代码行数:19,代码来源:laserxa.hpp

示例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);
     }
 }
开发者ID:thinks,项目名称:las,代码行数:16,代码来源:las10_read.hpp

示例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;
    }
开发者ID:gurpreet395,项目名称:Robo-Human-Handover,代码行数:15,代码来源:HumanHand.cpp

示例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;
}
开发者ID:labp,项目名称:na-online_ow-toolbox,代码行数:24,代码来源:WLMatLib_MATReader.cpp

示例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!";
  }
开发者ID:stinkytoe,项目名称:xcp,代码行数:24,代码来源:copier.hpp

示例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);
        }
开发者ID:WowDevs,项目名称:CascLib-1,代码行数:15,代码来源:Lookup3.hpp

示例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
}
开发者ID:LazyNarwhal,项目名称:Destination_Toolkit,代码行数:24,代码来源:SoundEngine.cpp

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

示例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);
            }
        }
    }
开发者ID:edvorg,项目名称:cpp-drash,代码行数:16,代码来源:loadmeshobj.cpp


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