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


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

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


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

示例1: ReaderObject

ReaderObject
FileReader::parse(std::istream& stream)
{
  int c = stream.get();
  stream.unget();
  if (c == '{')
  {
    Json::Reader reader;
    Json::Value root;
    if (reader.parse(stream, root))
    {
      return ReaderObject(std::make_shared<JsonReaderObjectImpl>(root));
    }
    else
    {
      log_error("json parse error: %1%", reader.getFormattedErrorMessages());
      return ReaderObject();
    }
  }
  else
  {
    std::shared_ptr<lisp::Lisp> sexpr = lisp::Parser::parse(stream, "<stream>");
    if (sexpr)
    {
      return ReaderObject(std::make_shared<SExprReaderObjectImpl>(sexpr->get_list_elem(0)));
    }
    else
    {
      log_error("sexpr parse error");
      return ReaderObject();
    }
  }
}
开发者ID:fsantanna,项目名称:pingus,代码行数:33,代码来源:file_reader.cpp

示例2: TestComment

char SplineGeometry::TestComment(std::istream& infile)
{
    bool comment = true;
    char ch = '\0';
    while (comment && !infile.eof()) {
        infile >> ch;
        if (ch == '#') {
            // skip comments
            while (ch != '\n' && !infile.eof()) {
                infile.get(ch);
            }
        } else if (ch == '\n') {
            // skip empty lines
        } else if (isblank(ch)) {
            // skip whitespaces
        } else if (ch == '-') {
            // do not unget '-'
            comment = false;
        } else {
            // end of comment
            infile.unget();
            comment = false;
        }
    }
    return ch;
}
开发者ID:honnorat,项目名称:meshit,代码行数:26,代码来源:geometry2d.cpp

示例3: runtime_error

int Midi::Event::Parse(std::istream &f, int running)
{
	delta = read_vl(f);
	int p = f.get();
	type = p >> 4;
	if(!(type & 0x8))
	{
		type = running;
		f.unget();
	}
	if(type == Midi::Event::Extra)
	{
		f.ignore(1);
		int length = f.get();
		f.ignore(length);
	}
	else
	{
		param1 = f.get();
		param2 = f.get();
	}
	if(f.eof())
		throw std::runtime_error("Cannot read event: file truncated");
	return type;
}
开发者ID:mniip,项目名称:fdmp,代码行数:25,代码来源:Midi.cpp

示例4: rollbackStream

/**
 * Method rolls back in passed std::istream-e by passed number of read characters.
 *
 * @param stream reference to stream which will be rolled back.
 * @param size the value representing number of characters we want to roll back.
 */
void CiscoInputParser::rollbackStream(std::istream& stream, std::streamsize size)
{
    for ( streamsize i = 0; i < size; ++i )
    {
        stream.unget();
    }
}
开发者ID:Gaojiaqi,项目名称:acl-check,代码行数:13,代码来源:CiscoInputParser.cpp

示例5: skip_comment

// helper function: skip commment lines in the header of ppm image
void PPM_Image::skip_comment(std::istream &is) {
    char c; is >> c;
    while (c == '#') { // skipping comment lines
        is.ignore(256, '\n');
        is >> c;
    }
    is.unget();
}
开发者ID:Tigrolik,项目名称:Computer_graphics,代码行数:9,代码来源:PPM_Image.cpp

示例6: trim_whitespaces

void trim_whitespaces(std::istream& is) {
	while( is.good() ) {
		if(! std::isspace( is.get() ) ) {
			// When not space, go to previous character and break
			is.unget();
			return;
		}
	}
}std::istream& operator>>(std::istream& is, Matrix& m)
开发者ID:pascalc,项目名称:cprog11_lab1,代码行数:9,代码来源:oMatrix.cpp

示例7: read

int asn_object::read(std::istream& istr){
	char c1, c2;
	if(!(istr>>c1)){
		//istr.unget();
		return -1;
	}
	if(!(istr>>c2)){
		//istr.unget();
		istr.unget();
		return -1;
	}
	if(!isxdigit(c1) || !isxdigit(c2)){
		istr.unget();
		istr.unget();
		return -1;
	}
	return hex2int(c1)*16 + hex2int(c2);
}
开发者ID:macklo,项目名称:PROI_ASN,代码行数:18,代码来源:asn_object.cpp

示例8: lex_name

Token lex_name(std::istream& stream) {
    char c;
    std::string name;
    while (stream.get(c) && std::isalpha(c))
        name.push_back(c);

    if (stream)
        stream.unget();

    return {name_token, name};
}
开发者ID:EastcoastPhys,项目名称:linear-cpp,代码行数:11,代码来源:lex.cpp

示例9: lex_number

Token lex_number(std::istream& stream) {
    char c;
    std::string number;
    while (stream.get(c) && std::isdigit(c))
        number.push_back(c);

    if (stream)
        stream.unget();

    return {number_token, number};
}
开发者ID:EastcoastPhys,项目名称:linear-cpp,代码行数:11,代码来源:lex.cpp

示例10: lex_operator

Token lex_operator(std::istream& stream) {
    char c;
    std::string op;
    while (stream.get(c) && isoperator(c))
        op.push_back(c);

    if (stream)
        stream.unget();

    return {name_token, op};
}
开发者ID:EastcoastPhys,项目名称:linear-cpp,代码行数:11,代码来源:lex.cpp

示例11: getContinuousChar

	int getContinuousChar(std::istream& is, char c)
	{
		int count = 1;
		char p;
		while (is >> p) {
			if (p != c) break;
			count++;
		}
		is.unget();
		return count;
	}
开发者ID:Constellation,项目名称:xbyak,代码行数:11,代码来源:bf.cpp

示例12: if

std::shared_ptr<Object> read_character(std::istream &in) {
  std::stringstream buf;
  int c = in.get();
  if (in.eof()) {
    throw "EOF while reading character";
  }
  buf.put(c);
  for (; ;) {
    c = in.get();
    if (in.eof() || iswhitespace(c) || isterminator(c)) {
      in.unget();
      break;
    }
    buf.put(c);    
  }
  std::string token = buf.str();
  if (token.size() == 1) {
    return std::make_shared<Character>( token[0] );
  } else if (token == "newline") {
    return std::make_shared<Character>( '\n' );
  } else if (token == "space") {
    return std::make_shared<Character>( ' ' );
  } else if (token == "tab") {
    return std::make_shared<Character>( '\t' );
  } else if (token == "backspace") {
    return std::make_shared<Character>( '\b' );
  } else if (token == "formfeed") {
    return std::make_shared<Character>( '\f' );
  } else if (token == "return") {
    return std::make_shared<Character>( '\r' );
  } else if (token[0] == 'u') {
    long uc = read_unicode_char(token, 1, 4, 16);
    if (c >= 0xD800 && c <= 0xDFFF) {
      // TODO: java clojure actually prints u + the hex value of uc
      // is this any different than token?
      throw "Invalid character constant: \\" + token;
    }
    return std::make_shared<Character>( uc );
  } else if (token[0] == 'o') {
    int len = token.size() - 1;
    if (len > 3) {
      throw "Invalid octal escape sequence length: " + std::to_string(len);
    }
    long uc = read_unicode_char(token, 1, len, 8);
    if (uc > 0377) {
      throw "Octal escape sequence mst be in range [0, 377].";
    }
    return std::make_shared<Character>( uc );
  }
  throw "Unsupported character: \\" + token;
}
开发者ID:tristan,项目名称:cclojure,代码行数:51,代码来源:lispreader.cpp

示例13: readBranchLength

  double readBranchLength(std::istream &iss)
  {
    bool foundNext = false; 
    while(not foundNext)
      {
	int ch = iss.get(); 

	foundNext = ( ch == ')'
		      || ch == ';'
		      || ch == ',' ) ; 
      }
    iss.unget();
    return nan("");
  }
开发者ID:pombredanne,项目名称:exa-bayes,代码行数:14,代码来源:BranchLengthPolicy.hpp

示例14: goto_first_not_of

static bool goto_first_not_of(std::istream& s, const std::string& str)
{
	char c;
	while (s.get(c))
	{
		if (str.find(c) == std::string::npos)
		{
			s.unget();
			return true;
		}
	}
	
	return false;
}
开发者ID:ChristianFrisson,项目名称:gephex,代码行数:14,代码来源:streamtokenizer.cpp

示例15: undoScan

	void Scanner::undoScan(std::istream& stream, int character_count)
	{
		for ( int i = 0; i < character_count; i++ )
		{
			stream.unget();
			if ( stream.fail() == true )
			{
				stream.clear();
				this->end_of_file = false;
				stream.seekg(-(--character_count), std::ios::end);
				return;
			}
		}
	}
开发者ID:nephiw,项目名称:DNA-Sequencer,代码行数:14,代码来源:Scanner.cpp


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