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


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

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


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

示例1: br

R_Tree::R_Tree(std::ifstream& in)
{
  error_code = 0;
  tree = 0;
  reverse_bytes = false;
  f_offset = in.tellg();
  
  const unsigned int header_size = 48;
  char* header_bytes = new char[header_size];

  in.read(header_bytes, header_size);
  if(!in.good()){
    error_code = 1;
    std::cerr << "R_Tree Unable to read in index from file " << std::endl;
    delete []header_bytes;
    return;
  }
  
  header_magic = *(unsigned int*)header_bytes;
  if(header_magic != R_TREE_MAGIC){
    reverse_bytes = true;
    header_magic = __builtin_bswap32(header_magic);
  }
  if(header_magic != R_TREE_MAGIC){
    std::cerr << "R_Tree Unable to find correct magic got: " << header_magic
	      << "Wanted : " << R_TREE_MAGIC << std::endl;
    error_code = 2;
    delete []header_bytes;
    return;
  }
  
  ByteReader br(header_bytes, header_size, reverse_bytes);
  blockSize = br.ui(4);
  itemCount = br.ul(8);
  startChromIx = br.ui(16);
  startBase = br.ui(20);
  endChromIx = br.ui(24);
  endBase = br.ui(28);
  endFileOffset = br.ul(32);
  itemsPerSlot = br.ui(40);
  reserved = br.ui(44);
  
  delete []header_bytes;
  tree = new R_TreeNode(in, 0, in.tellg(), reverse_bytes);
}
开发者ID:lmjakt,项目名称:BbiParser,代码行数:45,代码来源:R_Tree.cpp

示例2: 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

示例3: getFileLength

	unsigned long getFileLength(std::ifstream& file)
	{
		if(!file.good()) return 0;

		file.seekg(0, std::ios::end);
		std::streamoff len = file.tellg();
		file.seekg(std::ios::beg);
		return (unsigned long)len;
	}
开发者ID:zeoverlord,项目名称:glz-core,代码行数:9,代码来源:shader.cpp

示例4: ParseSpecularColor

//father:Material Block
//child	: sub color chunk
void ParseSpecularColor()
{
	uint64_t filePos = 0;
	do
	{
		ReadAndParseColorChunk(static_materialList.back().baseMaterial.mBaseSpecularColor);
		filePos = fileIn.tellg();
	} while (filePos<static_currentChunkFileEndPos);
}
开发者ID:CHINA-JIGE,项目名称:Noise3D-DirectX11,代码行数:11,代码来源:NBASE_FileMgr_3DS.cpp

示例5: copyKeyword

static void copyKeyword( std::ifstream& is , std::ofstream& os) {
  std::ios::pos_type start_pos = is.tellg();
  skipKeyword( is );
  {
    std::ios::pos_type end_pos = is.tellg();
    long length = end_pos - start_pos;
    
    {
      char * buffer = new char[length];
      {
        is.seekg( start_pos );
        is.read( buffer , length );
      }
      os.write( buffer , length );
      delete[] buffer;
    }
  }
}
开发者ID:hnil,项目名称:opm-core,代码行数:18,代码来源:import_rewrite.cpp

示例6: map_file

/**
 * @brief read correlator meta-data and map to file positions
 * @description Nissa text correlator files contain meta-data in the form
 *              of comment lines. One line gives information about the
 *              contracted propagators in the form
 *
 *                S0_th0_m0_r0_ll ^ \dag S0_th0_m0_r0_ll
 *
 *              where we are (currently) interested in the indices
 *              on the m and r tokens. Another comment line specifies
 *              the spin content of the correlator in the form
 *              "P5P5" or "V1A0", for example. This function
 *              reads through the whole file and extracts the two
 *              m and two r indices as well as the spin combination.
 *              It constructs a key based on this information and stores
 *              the file position of the character after the newline behind
 *              the spin combination tag. Thus it stores the position of the
 *              beginning of the correlator corresponding to the constructed key.
 *
 * @param ifs file to be parsed
 * @param filemap output, map of file positions for the various correlators in the file
 */
inline void map_file(std::ifstream &ifs, std::map<std::string, std::iostream::pos_type> & filemap){
  if( !ifs.good() ){
    stop("map_file: input file stream not in a good state!");
  }

  std::string linebuf;
  std::string::size_type comment_pos;

  // currently the key for a two-point function consists of four unsigned integers (two mass and two r indices)
  // and the name of the spin combination stored in the correlator
  // a generalisation of the reader will have to modify this as well as the key construction
  // for now we store the numeric key components in this array
  unsigned int key_components[4];

  while( ifs.good() ){
    std::getline(ifs, linebuf);
    // we search for commented lines
    comment_pos = linebuf.find("#");
    if( comment_pos != std::string::npos ){
      // in these commented lines, we extract either
      // the current set of mass / r parameter combinations
      // or the current spin combination
      // the line looks like so:
      // " # Contraction of S0_th0_m0_r0_ll ^ \dag and S0_th0_m0_r0_ll"
      std::string::size_type contr_pos = linebuf.find("Contraction");
      if( contr_pos != std::string::npos ){
        std::vector<char> lbcopy( linebuf.size() + 1 );
        lbcopy[ linebuf.size() ] = '\0';
        memcpy( lbcopy.data(), linebuf.c_str(), linebuf.size() );
        unsigned int key_components_counter = 0;
        char * token = strtok(lbcopy.data(), "_");
        while( key_components_counter != 4 | token != NULL ){
          if( token[0] == 'm' || token[0] == 'r'){
            key_components[key_components_counter] = atoi(token+1);
            key_components_counter++;
          }
          token = strtok(NULL, "_");
        }
        if(key_components_counter != 4 && token == NULL){
          char message[200];
          snprintf(message, 200, "map_file: unable to construct key components in parsing of '%s'", linebuf.c_str());
          stop(message);
        }
      } else {
        // the line looks like so:
        // " # P5S0"
        std::string::size_type last_space_pos = linebuf.find_last_of(" ");
        std::string spin_comb = linebuf.substr(last_space_pos+1);
        // now we can build the key
        std::string key = make_key_2pt(key_components[0], key_components[2], key_components[1], key_components[3], spin_comb);
        // and store the position after the current newline as the starting point
        // of the present correlator
        filemap[ key ] = ifs.tellg();
      }
    }
  }
}
开发者ID:etmc,项目名称:hadron,代码行数:79,代码来源:read_nissa_textcf_kernel.cpp

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

示例8: getFileLength

	unsigned long Shader::getFileLength(std::ifstream& in)
	{
		if (!in.good()) return 0;

		in.seekg(0, in.end);
		unsigned long length = in.tellg();
		in.seekg(0, in.beg);

		return length;
	}
开发者ID:Ninespin,项目名称:ultimate-snake,代码行数:10,代码来源:Shader.cpp

示例9: init

    /**
     * initialize the laserxa files
     */
    void
    init ()
    {
      // read the info header
      this->close ();
      file_in_.open (filename_, std::ios::in | std::ios::binary);
      file_in_.seekg (0, std::ios::beg);
      file_in_.read ((char*) &info_, sizeof(LaserxaInfo));

      // length of size
      auto current_pos = file_in_.tellg ();
      file_in_.seekg (0, std::ios::end);
      auto end = file_in_.tellg ();

      data_count_ = (static_cast<size_t> (end)
	  - static_cast<size_t> (current_pos)
	      / static_cast<size_t> (sizeof(LaserxaData)));

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

示例10: getFileSize

int GetCommand::getFileSize(std::ifstream &ifs)
{

       	//http://washieagle.blogspot.jp/2010/01/stdfstream.html
	int eofPos;
	int begPos;
	
	//末尾
	ifs.seekg(0, std::ifstream::end);
	eofPos = ifs.tellg();
		
	ifs.clear();
	
	//先頭
	ifs.seekg(0, std::ifstream::beg);
	begPos = ifs.tellg();

	return eofPos - begPos;
}
开发者ID:ytn86,项目名称:LikeFTP,代码行数:19,代码来源:getCommand.cpp

示例11: open

		bool open(const char* path) {
			std::streampos tmp,tmp2;
			close();
			m_fp.close();
			m_fp.open(path,std::ios::binary);

			if (!m_fp.is_open())
				return false;

			m_fp.seekg(0,std::ios::beg);
			tmp = m_fp.tellg();
			m_fp.seekg(0,std::ios::end);
			tmp2 = m_fp.tellg();
			m_fp_size = (uint64_t)(tmp2 - tmp);
			m_fp.seekg(0,std::ios::beg);
			m_fp_offs = 0U;

			return true;
		}
开发者ID:DimitrisVlachos,项目名称:lib_bitstreams,代码行数:19,代码来源:file_stream.hpp

示例12: getFileLength

unsigned long jE::getFileLength(std::ifstream& file)
{
    if(!file.good()) return 0;

    //unsigned long pos=file.tellg();
    file.seekg(0, std::ios::end);
    unsigned long len = file.tellg();
    file.seekg(std::ios::beg);

    return len;
}
开发者ID:jacquesrott,项目名称:libjEngine,代码行数:11,代码来源:tools.cpp

示例13: qstr

Csv_input_pointset_dialog::Csv_input_pointset_dialog( std::ifstream& infile,
        QWidget* parent ,
        const char* name )
    : QWidget( parent) {

    setupUi(this);

    std::streampos mark = infile.tellg();
    std::string str;
    std::getline(infile, str);
    QString qstr(str.c_str());

//  QTextStream inFileStream(infile,QIODevice::ReadWrite);
//  QString str;
//  inFileStream >> str;
//  inFileStream.readLine();
    QStringList property_names = qstr.split(",");


    X_col_name_->addItems(property_names);
    X_col_name_->addItem("None");
    Y_col_name_->addItems(property_names);
    Y_col_name_->addItem("None");
    Z_col_name_->addItems(property_names);
    Z_col_name_->addItem("None");


    //Set default selection
    X_col_name_->setCurrentIndex(0);
    Y_col_name_->setCurrentIndex(std::min(1,property_names.size()));
    Z_col_name_->setCurrentIndex(std::min(2,property_names.size()));
    // make a preview of the file

    QString text;
    std::string line;

    int count = 0;
    const int limit = 50;

    // Read up to "limit" lines
    while( std::getline( infile, line ) && count < limit ) {
        line += "\n";
        text.append( line.c_str() );
        count ++;
    }

    text_preview_->setPlainText( text );

    // set the stream back to where it was
    infile.clear();
    infile.seekg( mark );

    name_->setFocus();
}
开发者ID:fnavarrov,项目名称:SGeMS,代码行数:54,代码来源:csv_filter_qt_dialogs.cpp

示例14: extract_information_from_binary

CPU::E_CPU PE::extract_information_from_binary(std::ifstream &file)
{
    RP_IMAGE_DOS_HEADER imgDosHeader = {0};
    RP_IMAGE_NT_HEADERS32 imgNtHeaders32 = {0};
    CPU::E_CPU cpu = CPU::CPU_UNKNOWN;

    std::cout << "Loading PE information.." << std::endl;

    /* Remember where the caller was in the file */
    std::streampos off = file.tellg();

    file.seekg(0, std::ios::beg);
    file.read((char*)&imgDosHeader, sizeof(RP_IMAGE_DOS_HEADER));

    file.seekg(imgDosHeader.e_lfanew, std::ios::beg);
    /* 
     * Yeah, in fact, we don't know yet if it is a x86/x64 PE ; 
     * so just we grab the signature field, FILE_HEADER and the field Magic 
     */
    file.read((char*)&imgNtHeaders32, sizeof(unsigned int) + sizeof(RP_IMAGE_FILE_HEADER) + sizeof(unsigned int));
    
    if(imgNtHeaders32.Signature != RP_IMAGE_NT_SIGNATURE)
        RAISE_EXCEPTION("This file doesn't seem to be a correct PE (bad IMAGE_NT_SIGNATURE)");

    switch(imgNtHeaders32.OptionalHeader.Magic)
    {
        case RP_IMAGE_NT_OPTIONAL_HDR32_MAGIC:
        {
            cpu = CPU::CPU_x86;
            /* Ok, now we can allocate the good version of the PE Layout */
            /* The 32bits version there! */
            init_properly_PELayout<x86Version>();
            break;
        }

        case RP_IMAGE_NT_OPTIONAL_HDR64_MAGIC:
        {
            cpu = CPU::CPU_x64;
            init_properly_PELayout<x64Version>();
            break;
        }

        default:
            RAISE_EXCEPTION("Cannot determine the CPU type");
    }
    
    /* Now we can fill the structure */
    std::memcpy(&m_pPELayout->imgDosHeader, &imgDosHeader, m_pPELayout->get_image_dos_header_size());

    m_pPELayout->fill_nt_structures(file);

    file.seekg(off);
    return cpu;
}
开发者ID:haofree,项目名称:rp,代码行数:54,代码来源:pe.cpp

示例15: ParseSpecularMap

//father:Material Block
//child	: Mapping File Path  (Map option) 
void ParseSpecularMap()
{
	//data:sub chunks
	uint64_t filePos = 0;
	do
	{
		//mapName-mapFilePath pair will be added in this function
		ReadAndParseMapChunk(static_materialList.back().specularMapName);
		filePos = fileIn.tellg();
	} while (filePos<static_currentChunkFileEndPos);
}
开发者ID:CHINA-JIGE,项目名称:Noise3D-DirectX11,代码行数:13,代码来源:NBASE_FileMgr_3DS.cpp


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