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


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

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


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

示例1: LoadNextSeq

// Load next chromosome
ref_loc_t RefSeq::LoadNextSeq(std::ifstream &fin) {
    char c;
    char ch[1000];
    std::string s;
    fin>>c;
    if (fin.eof()) return 0;
    _length = 0;
    // get name
    fin>>_name;
    fin.getline(ch, 1000);
    // get seq
    while (!fin.eof()) {
        fin>>c;  
        if (fin.eof()) break;
        fin.unget();
        if (c == '>') break;
        fin>>s;
        if (_length + s.size() >= param.max_dbseq_size) {
            if (s.size() > param.append_dbseq_size) {
                param.max_dbseq_size += (s.size() + 10);
            } else { 
                param.max_dbseq_size += param.append_dbseq_size; 
            }
            _seq.resize(param.max_dbseq_size);
        }
        copy(s.begin(), s.end(), _seq.begin() + _length);
        _length += s.size();
    }
    return _length;
}
开发者ID:Al3n70rn,项目名称:msisensor,代码行数:31,代码来源:refseq.cpp

示例2: load_ref

    void load_ref( std::ifstream &is ) {
        size_t num_ref;
        is >> num_ref;
        m_ref_pvecs.resize( num_ref );
        m_ref_aux.resize( num_ref );
        
        for( size_t i = 0; i < m_ref_pvecs.size(); ++i ) {
            size_t len;
            is >> len;
            while( isspace( is.get() ) && !is.eof() ) {}
            is.unget();
            
            if( is.eof() ) {
                throw std::runtime_error( "unexpected end of file" );
            }
            
            m_ref_pvecs[i].resize(len);
            is.read( (char*)&m_ref_pvecs[i][0], len * sizeof(int) );
            
            m_ref_aux[i].resize(len);
            is.read( (char*)&m_ref_aux[i][0], len * sizeof(unsigned int) );
            
//             std::cout << "ref: " << i << " " << m_ref_pvecs[i].size() << "\n";
        }
        
    }
开发者ID:bowmanjeffs,项目名称:papara_nt,代码行数:26,代码来源:testbench.cpp

示例3: _nextToken

	void ConfigLoader::_nextToken(std::ifstream &stream)
	{
		lastTok = tok;
		lastTokVal = tokVal;
 
		//EOF token
		if (stream.eof())
		{
			tok = TOKEN_EOF;
			return;
		}
 
		//(Get next character)
		int ch = stream.get();
		if (ch == -1)
		{
			tok = TOKEN_EOF;
			return;
		}
		while ((ch == ' ' || ch == 9) && !stream.eof())
		{    //Skip leading spaces / tabs
			ch = stream.get();
		}
 
		if (stream.eof())
		{
			tok = TOKEN_EOF;
			return;
		}
 
		//Newline token
		if (ch == '\r' || ch == '\n')
		{
			do
			{
				ch = stream.get();
			} while ((ch == '\r' || ch == '\n') && !stream.eof());
 
			stream.unget();
 
			tok = TOKEN_NewLine;
			return;
		}
 
		//Open brace token
		else if (ch == '{')
		{
			tok = TOKEN_OpenBrace;
			return;
		}
 
		//Close brace token
		else if (ch == '}')
		{
			tok = TOKEN_CloseBrace;
			return;
		}
 
		//Text token
		if (ch < 32 || ch > 122)    //Verify valid char
		{
            throw std::runtime_error("Parse Error: Invalid character, ConfigLoader::load()");
		}
 
		tokVal = "";
		tok = TOKEN_Text;
		do
		{
			//Skip comments
			if (ch == '/')
			{
				int ch2 = stream.peek();
 
				//C++ style comment (//)
				if (ch2 == '/')
				{
					stream.get();
					do
					{
						ch = stream.get();
					} while (ch != '\r' && ch != '\n' && !stream.eof());
 
					tok = TOKEN_NewLine;
					return;
				}
			}
 
			//Add valid char to tokVal
			tokVal += (char)ch;
 
			//Next char
			ch = stream.get();
 
		} while (ch > 32 && ch <= 122 && !stream.eof());
 
		stream.unget();
 
		return;
	}
开发者ID:JonathanOhara,项目名称:CGFinalWork,代码行数:99,代码来源:ConfigLoader.cpp


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