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


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

本文整理汇总了C++中std::ifstream::read方法的典型用法代码示例。如果您正苦于以下问题:C++ ifstream::read方法的具体用法?C++ ifstream::read怎么用?C++ ifstream::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::ifstream的用法示例。


在下文中一共展示了ifstream::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
	}

	file.seekg(0, std::ios::end);
	int filesize = file.tellg();
	file.seekg(0, std::ios::beg);
	// make sure the region file has a header
	if (filesize < 8192) {
		return false;
	}

	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(reinterpret_cast<char*>(&tmp), 4);
			if (tmp == 0)
				continue;
			int offset = util::bigEndian32(tmp << 8) * 4096;
			//uint8_t sectors = ((uint8_t*) &tmp)[3];

			file.seekg(4096, std::ios::cur);
			int timestamp;
			file.read(reinterpret_cast<char*>(&timestamp), 4);
			timestamp = util::bigEndian32(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:CarterGC,项目名称:mapcrafter,代码行数:48,代码来源:region.cpp

示例2: decodeSubMesh

void Mz::decodeSubMesh( std::ifstream& f, int s )
{
	if (mVersion >= 20)
	{
		mSubmeshes.resize(s / sizeof(sSubMesh), sSubMeshWithName());
		size_t i = 0;
		while (s > 0)
		{
			f.read((char*)&mSubmeshes[i], sizeof(sSubMesh));
			f.read(mSubmeshes[i].name, mSubmeshes[i].nameLen);

			s -= (sizeof(sSubMesh) + mSubmeshes[i].nameLen);

			++i;
		}
		mSubmeshes.resize(i);
	} 
	else
	{
		mSubmeshes.resize(s / sizeof(sSubMeshWithName_V3), sSubMeshWithName());
		size_t i = 0;
		sSubMeshWithName_V3 v3;
		while (s > 0)
		{
			f.read((char*)&v3, sizeof(sSubMeshWithName_V3));
			memcpy(&mSubmeshes[i], &v3, sizeof(sSubMesh) - sizeof(u8));
			mSubmeshes[i].nameLen = strlen(v3.name);
			memcpy(mSubmeshes[i].name, v3.name, sizeof(mSubmeshes[i].name));
			s -= sizeof(sSubMeshWithName_V3);

			++i;
		}
	}
	for(int i = 0; i != mSubmeshes.size(); ++i)
	{
		sSubMeshWithName& s = mSubmeshes[i];
		for(int k = 0; k != 128; ++k)
		{
			if(s.name[k] == '|' || s.name[k] == ' ')
			{
				s.name[k] = '_';
			}
		}
	}
}
开发者ID:cpzhang,项目名称:zen,代码行数:45,代码来源:Mz.cpp

示例3: buffer

void
Producer::populateSegments(std::ifstream& ifs)
{
  BOOST_ASSERT(m_segments.size() == 0);

  // calculate how many segments are needed
  std::streampos begin, end;
  begin = ifs.tellg();
  ifs.seekg(0, std::ios::end);
  end = ifs.tellg();

  int num_segments = (end-begin) / m_maxSegmentSize;
  if ((end-begin) % m_maxSegmentSize != 0)
    num_segments++;

  std::cout << "Size of the file: " << (end-begin) << " bytes." << std::endl;
  std::cout << "Maximum size of a segment: " << m_maxSegmentSize << " bytes." << std::endl;
  std::cout << "Number of segments: " << num_segments << std::endl;

  std::vector<uint8_t> buffer(m_maxSegmentSize);
  ifs.seekg(0, std::ios::beg);
  for (int i = 0; i < (end-begin) / m_maxSegmentSize; ++i) {
    ifs.read(reinterpret_cast<char*>(buffer.data()), m_maxSegmentSize);
    auto data = make_shared<Data>(Name(m_prefix).appendSegment(i));
    data->setFreshnessPeriod(m_freshnessPeriod);
    data->setContent(&buffer[0], m_maxSegmentSize);
    //std::cout << *data << std::endl;
    m_segments.push_back(data);
  }

  if ((end-begin) % m_maxSegmentSize != 0) {
    ifs.read(reinterpret_cast<char*>(buffer.data()), (end-begin) % m_maxSegmentSize);
    auto data = make_shared<Data>(Name(m_prefix).appendSegment(m_segments.size()));
    data->setFreshnessPeriod(m_freshnessPeriod);
    data->setContent(&buffer[0], (end-begin) % m_maxSegmentSize);
    //std::cout << *data << std::endl;
    m_segments.push_back(data);
  }

  auto finalBlockId = name::Component::fromSegment(m_segments.size() - 1);
  for (const auto& data : m_segments) {
    data->setFinalBlockId(finalBlockId);
    m_keyChain.sign(*data, m_signingInfo);
  }
}
开发者ID:imsure,项目名称:ndn_cc,代码行数:45,代码来源:producer.cpp

示例4:

/*
 * Read a string from the file stream.
 */
std::string FileInput::ReadString8(std::ifstream &instr, int32_t len)
{
	char *buf = new char [len+1];
	instr.read(buf, len);
	buf[len]=0;
	std::string s=buf;
	delete[] buf;
	return s;
}
开发者ID:HenrikBengtsson,项目名称:affxparser,代码行数:12,代码来源:FileInput.cpp

示例5: Exception

	/**@brief read one char from file handle
	 *
	 * @return read a char read from file_
	 */
	inline const unsigned char nextChar()
	{
		char out;
		if (file_.read(&out, 1)) {
			return out;
		} else {
			throw Exception(__PRETTY_FUNCTION__, "Error reading file.");
		}
	}
开发者ID:weng-lab,项目名称:TwoBit,代码行数:13,代码来源:TwoBitFile.hpp

示例6: sizeof

static void loadVec3Array(std::ifstream& fin, std::vector<ml::vec3f>& array) {
    int array_size;
    fin.read((char*)(&array_size), sizeof(int));
    array.resize(array_size);
    for (int i = 0; i < array_size; ++i) {
        loadVec3(fin, array[i]);
    }
    return;
}
开发者ID:caomw,项目名称:activity-scene-modeling,代码行数:9,代码来源:sceneTemplate.cpp

示例7: readNullTermString

// Helper function to read a null terminated c-str from an ifstream.
std::string readNullTermString(std::ifstream & fileHandle) {
	std::string value;
	while (true) {
		char c;
		fileHandle.read(&c, sizeof(char));
		if (c != '\0') { value.push_back(c); }
		else { return value; }
	}
}
开发者ID:vilhelmo,项目名称:simple_deep,代码行数:10,代码来源:deepio.cpp

示例8: parse

CartridgeHeader RomParser::parse(std::ifstream& rom)
{
    CartridgeHeader header;

    rom.seekg(0x100, std::ios::beg);
    rom.read((char*)&header, sizeof(CartridgeHeader));

    return header;
}
开发者ID:nnarain,项目名称:gameboy,代码行数:9,代码来源:rom_parser.cpp

示例9: read_bytes_from_stream

ByteString read_bytes_from_stream(std::ifstream& stream, size_t size)
{
	char* cbuff = new char[size];
	stream.read(cbuff, size);
	ByteString bytes(reinterpret_cast<uint8_t*>(cbuff), size);
	delete[] cbuff;

	return bytes;
}
开发者ID:Anxuiz,项目名称:Voxel-Research,代码行数:9,代码来源:MinecraftLoader.cpp

示例10: iReadByte

unsigned char iReadByte (std::ifstream & ifile)
{
  // will read 1 byte from the file
    char b;

    ifile.read(&b, 1);

    return b;
}
开发者ID:Wedjaa,项目名称:node-gdal,代码行数:9,代码来源:prologue.cpp

示例11: sizeof

BitVector::BitVector(std::ifstream& file) :
  rank_index(0), select_index(0)
{
  file.read((char*)&(this->size), sizeof(this->size));
  file.read((char*)&(this->items), sizeof(this->items));
  file.read((char*)&(this->number_of_blocks), sizeof(this->number_of_blocks));
  file.read((char*)&(this->block_size), sizeof(this->block_size));

  usint* array_buffer = new usint[this->block_size * this->number_of_blocks];
  file.read((char*)(array_buffer), this->block_size * this->number_of_blocks * sizeof(usint));
  this->array = array_buffer;

  this->integer_bits = length(this->size);
  this->samples = new ReadBuffer(file, 2 * (this->number_of_blocks + 1), this->integer_bits);

  this->indexForRank();
  this->indexForSelect();
}
开发者ID:migumar2,项目名称:uiHRDC,代码行数:18,代码来源:bitvector.cpp

示例12:

binary_reader::market_message::market_message( std::ifstream& _in )
    : m_type(readValue<boost::uint32_t>(_in))
    , m_time(readValue<boost::uint32_t>(_in))
    , m_len(readValue<boost::uint32_t>(_in))
{
    m_msg = new char[m_len + 1];
    _in.read(&m_msg[0], m_len);
    m_msg[m_len] = '\0';
}
开发者ID:Gedeon-by,项目名称:cpp_craft_0314,代码行数:9,代码来源:market_message.cpp

示例13: ParseCommon

bool VCFont::ParseCommon(std::ifstream& f)
{
	char blockType = ReadInt8(f);
	int blockSize = ReadInt32(f);

	f.read((char*) &Common, 15);
	
	return true;
}
开发者ID:AThilenius,项目名称:VoxelCraft,代码行数:9,代码来源:VCFont.cpp

示例14: reset

/*---------------------------------------------------------*/
bool NOMAD::Cache_File_Point::read ( std::ifstream & fin )
{
  reset();

  // 1. _eval_status:
  fin.read ( (char *) &_eval_status , sizeof(_eval_status) );
  if ( fin.fail() || _eval_status > 3 )
    return false;

  // 2. _n:
  fin.read ( (char *) &_n , sizeof(_n) );
  if ( fin.fail() || _n <= 0 ) {
    _n = 0;
    return false;
  }

  // 3. _m:
  fin.read ( (char *) &_m , sizeof(_m) );
  if ( fin.fail() || _m < 0 ) {
    _n = _m = 0;
    return false;
  }

  // 4. _m_def:
  fin.read ( (char *) &_m_def , sizeof(_m_def) );
  if ( fin.fail() || _m_def < 0 ) {
    _m_def = _n = _m = 0;
    return false;
  }

  // 5. _coords:
  _coords = new double [_n];
  fin.read ( (char *) _coords , _n*sizeof(double) );
  if ( fin.fail() ) {
    reset();
    return false;
  }

  if ( _m_def > 0 ) {

    // 6. _bb_def:
    _bbo_def = new double [_m_def];
    fin.read ( (char *) _bbo_def , _m_def*sizeof(double) );
    if ( fin.fail() ) {
      reset();
      return false;
    }
  
    // 7. _bbo_index:
    _bbo_index = new int [_m_def];
    fin.read ( (char *) _bbo_index , _m_def*sizeof(int) );
    if ( fin.fail() ) {
      reset();
      return false;
    }
  }

  return true;
}
开发者ID:martinjrobins,项目名称:dakota,代码行数:60,代码来源:Cache_File_Point.cpp

示例15: nextElement

bool WLMatLib::MATReader::readMatrixDouble( Eigen::MatrixXd* const matrix, const ElementInfo_t& element, std::ifstream& ifs,
                const FileInfo_t& info )
{
    // Check some errors //
    // ----------------- //
    if( matrix == NULL )
    {
        wlog::error( LIBNAME ) << "Matrix object is null!";
        return false;
    }

    if( info.fileSize <= static_cast< size_t >( element.posData ) )
    {
        wlog::error( LIBNAME ) << "Data position is beyond file end!";
        return false;
    }

    if( element.dataType != DataTypes::miMATRIX )
    {
        wlog::error( LIBNAME ) << "Data type is not a matrix: " << element.dataType;
        return false;
    }

    const mArrayType_t arrayType = ArrayFlags::getArrayType( element.arrayFlags );
    if( arrayType != ArrayTypes::mxDOUBLE_CLASS )
    {
        wlog::error( LIBNAME ) << "Numeric Types does not match!";
        return false;
    }

    const std::streampos pos = ifs.tellg();

    // Read data //
    // --------- //
    ifs.seekg( element.posData );
    mDataType_t type;
    mNumBytes_t bytes;
    if( !readTagField( &type, &bytes, ifs ) )
    {
        wlog::error( LIBNAME ) << "Could not read Data Element!";
        ifs.seekg( pos );
        return false;
    }
    if( type != DataTypes::miDOUBLE )
    {
        wlog::error( LIBNAME ) << "Numeric Types does not match or compressed data, which is not supported: " << type;
        ifs.seekg( pos );
        return false;
    }

    matrix->resize( element.rows, element.cols );
    ifs.read( ( char* )matrix->data(), bytes );

    nextElement( ifs, element.posData, bytes );
    return true;
}
开发者ID:labp,项目名称:na-online_ow-toolbox,代码行数:56,代码来源:WLMatLib_MATReader.cpp


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