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


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

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


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

示例1:

TagPayloadCompound::TagPayloadCompound(istream& inStream){
	char nxtByte = inStream.peek();
	while(static_cast<TAG_TypeID>(nxtByte) != TAG_End){
		payload.push_back(NBTTag(inStream));
		nxtByte = inStream.peek();
	}
}
开发者ID:Brent-S,项目名称:Minecraft-Geographic-Generator,代码行数:7,代码来源:NBTTagNew.cpp

示例2: read

    bool Response::read(istream& str)
      {
        ACE_CString version;
        ACE_CString status;
        ACE_CString reason;

        int ch =  str.peek ();
        if (ch == eof_)
          {
            str.get (); // skip to eof
            return false;
          }
        // skip whitespace
        while (ACE_OS::ace_isspace (str.peek ()))
          {
            str.get ();
          }
        // get version
        ch = this->read_ws_field (str, version, MAX_VERSION_LENGTH);
        if (ch == eof_  || !ACE_OS::ace_isspace (ch))
          return false; // invalid HTTP version string
        // skip whitespace
        while (ACE_OS::ace_isspace (str.peek ()))
          {
            str.get ();
          }
        // get status
        ch = this->read_ws_field (str, status, MAX_STATUS_LENGTH);
        if (ch == eof_ || !ACE_OS::ace_isspace (ch))
          return false; // invalid HTTP status code
        // skip whitespace
        while (ACE_OS::ace_isspace (str.peek ()))
          {
            str.get ();
          }
        // get reason
        ch = this->read_field (str, reason, MAX_REASON_LENGTH, '\r');
        if (ch == '\r')
          ch = str.get (); // get lf
        if (ch != '\n')
          return false; // HTTP reason string too long

        INET_DEBUG (6, (LM_DEBUG, DLINFO
                        ACE_TEXT ("ACE_INet_HTTP: <-- %C %C %C\n"),
                        version.c_str (),
                        status.c_str (),
                        reason.c_str()));

        // get header lines
        if (!Header::read (str))
          return false;
        // skip empty line
        ch = str.get ();
        while (ch != '\n' && ch != eof_)
          ch = str.get ();
        this->set_version(version);
        this->status_.set_status (status);
        this->status_.set_reason (reason);
        return true;
      }
开发者ID:DOCGroup,项目名称:ACE_TAO,代码行数:60,代码来源:HTTP_Response.cpp

示例3: atoi

bool t_dir_graph::read_format2(istream& input, const string first_line){
	vector<t_vertex> verts;
	int adj;
	t_vertex v;
	uint datas = atoi(first_line.c_str());

	while(input.peek() == '\n') input.ignore(1); // read the '\n'
	// read vertices
	for(uint i = 0; i < datas; i++){
		input >> v;
		verts.push_back(v);
		while(input.peek() == '\n') input.ignore(1); // read the '\n'
	}
	for(uint i=0; i < verts.size(); i++) insert_vertex(verts[i]);
	// read adjacency matrix
	for(uint i=0; i < verts.size(); i++){
		for(uint j=0; j < verts.size(); j++){
			input >> adj;
			if(adj > 0)
				insert_arc(t_arc(verts[i], verts[j]));
			while(input.peek() == ' ') input.ignore(1); // read the ' '
			while(input.peek() == '\n') input.ignore(1); // read the '\n'
		}
	}
	return true;
}
开发者ID:igel-kun,项目名称:transEd,代码行数:26,代码来源:digraph.cpp

示例4: readQuotedString

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string Properties::readQuotedString(istream& in)
{
  char c;

  // Read characters until we see a quote
  while(in.get(c))
  {
    if(c == '"')
      break;
  }

  // Read characters until we see the close quote
  string s;
  while(in.get(c))
  {
    if((c == '\\') && (in.peek() == '"'))
      in.get(c);
    else if((c == '\\') && (in.peek() == '\\'))
      in.get(c);
    else if(c == '"')
      break;
    else if(c == '\r')
      continue;

    s += c;
  }

  return s;
}
开发者ID:CraigularB,项目名称:Provenance,代码行数:30,代码来源:Props.cpp

示例5: eatWhiteSpaces

void eatWhiteSpaces (istream &input)
{
	while (input.peek() == 32 || 
		   input.peek () == 10 ||
		   input.peek () == 13)
		input.get();
}
开发者ID:FIZLIN,项目名称:data-structures,代码行数:7,代码来源:prefix.cpp

示例6: while

/**
 * \brief Tokenize a stream of XML by chopping it up into XMLTokens and
 *        returning a vector of these tokens.
 *
 * This function consumes all data in the stream
 */
vector<XMLToken>
XMLToken::tokenize(istream& istrm) {
  vector<XMLToken> tokens;
  while (istrm.good()) {
    chomp(istrm);
    if (!istrm.good()) break;

    // parse tag
    if (istrm.peek() == '<') {
      string tagname;
      bool isEndTag = false;

      istrm.get(); // skip <
      chomp(istrm);
      if (!istrm.good()) break;
      if (istrm.peek() == '/') {
          istrm.get(); // skip /
          isEndTag = true;
      }

      while (istrm.good() && (istrm.peek() != '>'))
          tagname += istrm.get();
      istrm.get(); // skip >
      tokens.push_back(XMLToken(tagname,isEndTag));
    } else {
      // parse string
      string buf = "";
      while (istrm.good() && (istrm.peek() != '<'))
          buf += istrm.get();
      tokens.push_back(XMLToken(buf));
    }
  }
  return tokens;
}
开发者ID:cooleel,项目名称:piranha,代码行数:40,代码来源:SimpleXML.cpp

示例7: getQueries

vector<vector<string> > getQueries(istream& input, int queryLines){

    vector<vector<string> > queries;

    for (size_t i = 0; i < queryLines; i++) {
        vector<string> singleQuery;
        string temp;

        while(input.peek() != '\n' && input.peek()>0){

            if(input.peek() == '.' || input.peek() == '~'){
                singleQuery.push_back(temp);
                temp.clear();
                input.get();
            }else{
                temp.push_back(input.get());
            }

        }

        singleQuery.push_back(temp);
        queries.push_back(singleQuery);
        input.get();



    }

    return queries;

}
开发者ID:jameogle,项目名称:codesnippets,代码行数:31,代码来源:htmlParse.cpp

示例8: translateStream

void translateStream(istream& inputStream, ostream& outputStream)
{
  int i = 0;
  char ch;
  const int maxLength = 70;
  char word[maxLength] = {""}, translated[maxLength] = {""};
  
  // no word case with eof handler
  while (!isalnum(inputStream.peek())){
    if (inputStream.eof()) return;
    inputStream.get(ch);
    outputStream << ch;
  }

  // word case to obtain words
  while (isalnum(inputStream.peek())){
    inputStream.get(word[i]);
    i++;
  }

  // obtain translation and send to output stream
  translateWord(word,translated);
  outputStream << translated;

  // recusive call
  translateStream(inputStream,outputStream);
}
开发者ID:bingweichen,项目名称:imperial_exams,代码行数:27,代码来源:piglatin.cpp

示例9: readUntilCloseChar

// reads chars from the stream until one of the closing chars is found
// (either a comma, closing bracket or closing brace).  The closing char
// is NOT consumed.  Function assumes the stream is pointing at the
// first character of the value.
// Note: This function is not used for strings.  See readString() for that.
string readUntilCloseChar(istream &istr) {
  string value;
  char next = static_cast<char>(istr.peek());
  while ((next != ',') && (next != '}') && (next != ']')) {
    if (istr.eof()) {
      throw JSONParseException(
          "Stream unexpectedly ended without a closing char.");
    }

    if ((value.size() > 0) ||
        (!isspace(
             next))) // don't add white space to the start of the value string
    {
      value += next;
    }
    istr.get(); // consume the char from the stream
    next = static_cast<char>(istr.peek());
  }

  // Strip any whitespace off the end of the value string
  while (isspace(value.back())) {
    value.pop_back();
  }

  return value;
}
开发者ID:liyulun,项目名称:mantid,代码行数:31,代码来源:SimpleJSON.cpp

示例10: while

//---------------------------------------------------------------------------
unique_ptr<Expression> ExpressionParser::parseSingleExpression(istream& input, ExpressionType lastExpression, Environment& environment)
{
   // read
   harriet::skipWhiteSpace(input);
   char a = input.get();
   if(!input.good())
      return nullptr;

   // other single letter operators
   if(a == '(') return make_unique<OpeningPharentesis>();
   if(a == ')') return make_unique<ClosingPharentesis>();
   if(a == '+') return make_unique<PlusOperator>();
   if(a == '-') { if(lastExpression==ExpressionType::TBinaryOperator || lastExpression==ExpressionType::TUnaryOperator || lastExpression==ExpressionType::TOpeningPharentesis) return make_unique<UnaryMinusOperator>(); else return make_unique<MinusOperator>(); }
   if(a == '*') return make_unique<MultiplicationOperator>();
   if(a == '/') return make_unique<DivisionOperator>();
   if(a == '%') return make_unique<ModuloOperator>();
   if(a == '^') return make_unique<ExponentiationOperator>();
   if(a == '&') return make_unique<AndOperator>();
   if(a == '|') return make_unique<OrOperator>();
   if(a=='>' && input.peek()!='=') return make_unique<GreaterOperator>();
   if(a=='<' && input.peek()!='=') return make_unique<LessOperator>();
   if(a=='!' && input.peek()!='=') return make_unique<NotOperator>();
   if(a=='=' && input.peek()!='=') return make_unique<AssignmentOperator>();

   // check for string
   char b = input.get();
   if(a=='"') {
      string result;
      while(b!='"' && a!='\\') {
         if(!input.good())
            throw harriet::Exception{"unterminated string expression"};
         result.push_back(b);
         a = b;
         b = input.get();
      }
      return make_unique<StringValue>(result);
   }

   // check for two signed letters
   if(input.good()) {
      if(a=='=' && b=='=') return make_unique<EqualOperator>();
      if(a=='>' && b=='=') return make_unique<GreaterEqualOperator>();
      if(a=='<' && b=='=') return make_unique<LessEqualOperator>();
      if(a=='!' && b=='=') return make_unique<NotEqualOperator>();
      input.unget();
   } else {
      input.clear();
   }

   // check for a number
   input.unget();
   if(isdigit(a)) {
      int32_t intNum;
      input >> intNum;
      if(input.peek()=='.' && input.good()) {
         float floatNum;
         input >> floatNum;
         return make_unique<FloatValue>(floatNum+intNum);
      } else {
         return make_unique<IntegerValue>(intNum);
开发者ID:alexandervanrenen,项目名称:Harriet,代码行数:61,代码来源:ExpressionParser.cpp

示例11: while

bool
fcnn::internal::read_comment(istream &is, string &s)
{
    if (!is.good() || is.eof()) return false;
    char c;
    s.clear();
    c = is.peek();
    if (c != '#') return false;
    is.get(c);

start_line:
    do { is.get(c); }
    while ((is.good() && !is.eof()) && ((c == ' ') || (c == '\t')));
    if (is.eof()) return true;
    if (is.fail()) return false;
    while ((is) && (c != '\n')) {
        s += c;
        is.get(c);
    }
    if (is.eof()) return true;
    if (is.fail()) return false;
    if (c == '\n') {
        if (is.peek() == '#') { s += c; goto start_line; }
        else return true;
    }
    return true;
}
开发者ID:bakaschwarz,项目名称:ptfc_fcnn,代码行数:27,代码来源:utils.cpp

示例12: while

void
SpatialDomain::ignoreCrLf(istream &in) {
  char c = in.peek();
  while (c == 10 || c == 13) {
    in.ignore();
    c = in.peek();
  }
}
开发者ID:esheldon,项目名称:misc,代码行数:8,代码来源:SpatialDomain.cpp

示例13: initFromStream

// Initialize a JSON object from a stream (presumably creating a whole
// hierarchy)
//
// This is the big one. :)  The expectation is that the first character
// will be a '{' and the function will run until if finds a matching '}'
// char.  Along the way, it may create nested objects and/or arrays
// (which means it may be called recursively - by way of
// initValueFromStream())
// Note: The function will consume the closing brace from the stream
void initFromStream(JSONObject &obj, istream &istr) {
  char nextChar;
  istr >> nextChar;
  checkChar(nextChar, '{'); // sanity check
  skipWhiteSpace(istr);

  // Check for empty object (and make sure we consume the })
  nextChar = static_cast<char>(istr.peek());
  if (nextChar == '}') {
    istr.ignore();
  }

  while (nextChar != '}') // process the stream
  {
    // Quick sanity check
    if (istr.eof()) {
      throw JSONParseException("Unexpected end of data stream");
    }

    // We expect to start the loop with the stream pointing to the opening quote
    // of the key
    nextChar = static_cast<char>(istr.peek());
    checkChar(nextChar, '"');

    string key = readString(istr);
    istr >> nextChar;         // >> operator automatically skips white space
    checkChar(nextChar, ':'); // the separator between the key and the value

    skipWhiteSpace(istr);

    // Now. we're at the start of the value.
    // Add the key and value to our object
    obj[key] = initValueFromStream(istr);
    istr >> nextChar;
    // nextChar is guaranteed to be either a comma, close brace or close
    // bracket.
    //(If it was anything else, initValueFromStream() would have thrown an
    // exception.)
    // A bracket is an error, a brace means the object is done (and will be
    // checked at
    // the start of the while loop) and a comma needs to be thrown out (along
    // with any
    // following whitespace) to position us for the next key/value pair
    if (nextChar == ']')
      throw JSONParseException(
          "Invalid closing bracket while initializing object");
    else if (nextChar == ',') {
      skipWhiteSpace(istr);
      // Check to see if another key/value pair really follows the comma
      // (because if one doesn't, the parser will get screwed up and may not
      // actually detect the problem).
      if (istr.peek() != '"') {
        throw JSONParseException(
            "Invalid comma (no key/value pair following it)");
      }
    }
  }
}
开发者ID:liyulun,项目名称:mantid,代码行数:67,代码来源:SimpleJSON.cpp

示例14: read

void Symbol::read(istream& in)
{
	char ch = in.peek();
	while(!isspace(ch) && (ch != '(') && (ch != ')'))
	{
		in.get(ch);
		name.push_back(ch);
		ch = in.peek();
	}
}
开发者ID:grablisting,项目名称:ray,代码行数:10,代码来源:symbol.cpp

示例15: skipwhite

void skipwhite(istream &s)
{
	s.get();
	return;
	while(s.peek()==' ' || s.peek()=='\t')
	{
		char c=s.get();
		cout<<"skip:"<<c<<endl;
	}
}
开发者ID:iFreeze-Qiu,项目名称:gcode2vtk,代码行数:10,代码来源:gcode2vtk.cpp


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