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


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

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


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

示例1: elemCount

GeometryLoaderDX11::PlyElementDesc GeometryLoaderDX11::ParsePLYElementHeader(std::string headerLine, std::ifstream& input)
{
	GeometryLoaderDX11::PlyElementDesc desc;
	std::string txt;

	// Parse the header line
	// "element <name> <count>"
	int split = headerLine.find_first_of(' ', 8);
	desc.name = headerLine.substr(8, split - 8);
		
	split = headerLine.rfind( ' ' );
	std::istringstream elemCount(headerLine.substr(split, headerLine.length() - split));
	elemCount >> desc.elementCount;

	// Parse any attached properties
	while(input.is_open() && !input.eof())
	{
		std::getline( input, txt );

		if(0 == txt.compare(0, 13, "property list"))
		{
			// Parse this property list declaration
			desc.dataFormat.push_back(ParsePLYElementPropertyList(txt.substr(14, txt.length() - 14)));
		}
		else if(0 == txt.compare(0, 8, "property"))
		{
			// Parse this property declaration
			desc.dataFormat.push_back(ParsePLYElementProperty(txt.substr(9, txt.length() - 9)));
		}
		else
		{
			// At this point we'll also have read a line too far so
			// need to "unread" it to avoid breaking remaining parsing.
			input.putback('\n');
			for(int i = -1 + txt.length(); i >= 0; i--)
				input.putback(txt.at(i));
			// (there must be a better way, no?!?)
			break;
		}
	}

	return desc;
}
开发者ID:CaptainJH,项目名称:hieroglyph3-90072,代码行数:43,代码来源:GeometryLoaderDX11.cpp

示例2:

// reads until first non-whitespace character
void MD5Model::skipWhitespace(std::ifstream &fin) {
	char c = '\0';
	while (!fin.eof()) {
		fin.get(c);

		if (!IS_WHITESPACE(c)) {
			fin.putback(c);
			break;
		}
	}
}
开发者ID:Jeromecen,项目名称:MD5SkeletalAnimation,代码行数:12,代码来源:MD5Model.cpp

示例3: readIntList

static void readIntList(std::vector<unsigned>& ints, std::ifstream& i) {
   std::string tok;
   while (i.good()) {
      i >> tok;
      if (isInt(tok)) {
         ints.push_back(atoi(tok.c_str()));
      } else {
         for (unsigned j=tok.size(); j>0; --j)
            i.putback(tok[j-1]);
         break;
      }
   }
}
开发者ID:RomanSchwienbacher,项目名称:DBI,代码行数:13,代码来源:Plan.cpp

示例4: Exception

void MD5Model::skipComments(std::ifstream &fin) {
	char c;
	fin.get(c);

	if (c != '/')
		throw Exception("MD5Model::skipComments(): invalid comment, expected //");

	while (!fin.eof() && c != '\n')
		fin.get(c);

	// put back last character read
	fin.putback(c);
}
开发者ID:Jeromecen,项目名称:MD5SkeletalAnimation,代码行数:13,代码来源:MD5Model.cpp

示例5: readDummy

void MovingMeshFB::readDummy(std::ifstream& is)
{
  char c;
  for (is.get(c);true;is.get(c)) {
    if (c == '#') {
      while (true) {
	is.get(c);
	if (c == '#') break;
      }
    }
    else if (('0' <= c && c <= '9')||(c == '.')||(c =='-'))
      break;
  }
  is.putback(c);		
}
开发者ID:volterra-luo,项目名称:z-afepack,代码行数:15,代码来源:MovingMeshFB.cpp

示例6: read_next_number

uint32_t read_next_number( std::ifstream & is ) {
    uint32_t value = 0;
    
    // Skip whitespace
    char c;
    while( ( is.get(c) ) && (c == ' ' || c == '\t' || c=='\n' || c == '\r' ) );
    while( c >= '0' && c <= '9' ) {
        value *= 10;
        value += ( c - '0' );
        is.get(c);
    }
    is.putback(c);
    
    return value;
}
开发者ID:Scoobadood,项目名称:tsdf,代码行数:15,代码来源:PgmUtilities.cpp

示例7: pnm_read

   void pnm_read(std::ifstream &file, char *buf)
   {
      char doc[PNM_BUFFER_SIZE];
      char c;

      file >> c;
      while (c == '#') {
         file.getline(doc, PNM_BUFFER_SIZE);
         file >> c;
      }
      file.putback(c);

      file.width(PNM_BUFFER_SIZE);
      file >> buf;
      file.ignore();
   }
开发者ID:HWiese1980,项目名称:insight3d,代码行数:16,代码来源:image_io_pnm.cpp

示例8: passWhiteSpaces

 inline void FileParse::passWhiteSpaces(std::ifstream& fin) {
   // Check for eof
   if (fin.eof()) return;
   char c;
   // Get first character
   fin.get(c);
   // Loop
   while (!fin.eof()) {
     if (c==' ' || c=='\n' || c=='\r');
     else { // Encountered a non-whitespace
       fin.putback(c);
       return;
     }
     // Get next character
     fin.get(c);
   }
 }
开发者ID:nrupprecht,项目名称:GFlow,代码行数:17,代码来源:fileparse.cpp

示例9: passSpaces

 inline bool FileParse::passSpaces(std::ifstream& fin) {
   char c;
   // Get first character
   fin.get(c);
   // Loop
   while (!fin.eof()) {
     if (c==' ');
     else if (c=='\n' || c=='\r') return true;
     else { // Encountered a non-whitespace
       fin.putback(c);
       return false;
     }
     // Get next character
     fin.get(c);
   }
   // Return success
   return true;
 }
开发者ID:nrupprecht,项目名称:GFlow,代码行数:18,代码来源:fileparse.cpp

示例10: getBody

 inline void FileParse::getBody(std::ifstream& fin) {
   // Look for heads
   char c;
   bool end = false;
   while (!fin.eof() && !end) {
     passWhiteSpaces(fin);
     if (!fin.eof()) fin.get(c);
     else return;
     if (c=='}') // End of a body
       return;
     else if (c=='/') { // Could be the start of a comment
       checkComment(fin);
     }
     else {
       fin.putback(c);
       getHead(fin);
     }
   }
 }
开发者ID:nrupprecht,项目名称:GFlow,代码行数:19,代码来源:fileparse.cpp

示例11: passComment

 inline void FileParse::passComment(std::ifstream& fin, bool mline) {
   string comment;
   // Start right after "//" or "/*"
   char c;
   fin.get(c);
   while (!fin.eof()) {
     if (mline && c=='*') {
       fin.get(c);
       if (fin.eof()) {
         // Message
         message += (tabs() + (mline ? "ML" : "SL") + " <" + comment +">\n");
         message += "--> EOF\n";
         // End of file encountered
         return; // Check end of file
       }
       if (c=='/') {
         // Message
         message += (tabs() + (mline ? "ML" : "SL") + " <" + comment +">\n");
         // End of the comment
         return; 
       }
       else message += ('*' + c);
     }
     else if (c=='\n' || c=='\r') {// Single line comments end with at newline
       if (mline) comment += "[\\n]";
       else {
         // Message
         message += (tabs() + (mline ? "ML" : "SL") + " <" + comment +">\n");
         // In case a newline signifies something for whoever called this function
         fin.putback(c); 
         return;
       }
     }
     else {
       if (c=='\t') comment += "[\\t]";
       else comment.push_back(c);
     }
     // Get next character
     fin.get(c);
   }
 }
开发者ID:nrupprecht,项目名称:GFlow,代码行数:41,代码来源:fileparse.cpp

示例12: ReadOpenClosePar

void CFileSystemLongArray::ReadLongArray2D( std::ifstream &stream,
		unsigned int nx, unsigned int ny, long *pdata )
{
std::string buffer;

while ( ReadOpenClosePar( stream ) != 0 )
        {
        ReadString( stream, buffer ); // str

        if ( g_verbose > 1)
                {
                std::cout << "Read token <" << buffer << ">\n";
                }

        switch( token_match( buffer, token_list, token_num ) )
                {
                case TOKEN_YSLICE:
                        if ( g_verbose > 1 )
                                {
                                std::cout << "Reading Y-slice\n";
                                }

                        ReadLongArray1D( stream, nx, pdata );
                        pdata += nx;
                        break;

                default:
                        std::cout << "ReadLongArray2D::Unknown token <";
                        std::cout << buffer.c_str() << " >\n";
                        break;
                }

        ReadClosePar( stream );       // }
        }

stream.putback( '}' );
}
开发者ID:mistalro,项目名称:openglextensionviewer,代码行数:37,代码来源:io_longarray.cpp

示例13: ReadFile

int CExtensionHeaderFileSettingsIODataAsciiIO::ReadFile( std::ifstream &stream )
{
int result;
std::string tokenid;

int entry_savedstates;

result = true;


if ( g_verbose )
	{
	std::cout << "Reading CExtensionHeaderFileSettingsIODataAsciiIO" << std::endl;
	}

while ( ReadOpenClosePar( stream ) != 0 )
	{
	ReadString( stream, tokenid );

	if ( g_verbose > 1 )
		{
		std::cout << "Read Token = <" << tokenid << ">\n";
		}

	switch( token_match( tokenid, token_list, token_num ) )
		{
		case TOKEN_SYSTEMLIST:
			m_systemlist.ReadFile( stream );

			if ( g_verbose )
				{
				std::cout << "Read <systemlist>\n";
				}
			break;

		case TOKEN_NEWLIST:
			m_newlist.ReadFile( stream );

			if ( g_verbose )
				{
				std::cout << "Read <newlist>\n";
				}
			break;

		case TOKEN_IGNORELIST:
			m_ignorelist.ReadFile( stream );

			if ( g_verbose )
				{
				std::cout << "Read <ignorelist>\n";
				}
			break;

		case TOKEN_VENDORLIST:
			m_vendorlist.ReadFile( stream );

			if ( g_verbose )
				{
				std::cout << "Read <vendorlist>\n";
				}
			break;

		case TOKEN_VERSIONLIST:
			m_versionlist.ReadFile( stream );

			if ( g_verbose )
				{
				std::cout << "Read <versionlist>\n";
				}
			break;

		case TOKEN_SAVEDSTATES:
			ReadInteger( stream, entry_savedstates );
			m_savedstates = entry_savedstates;

			if ( g_verbose )
				{
				std::cout << "Read <savedstates> = <" << entry_savedstates << ">\n";
				}
			break;

		default:
			std::cout << "CExtensionHeaderFileSetIO::Unknown token <" << tokenid << ">\n";
			break;
		}

	ReadClosePar( stream );
	}

stream.putback( '}' );

if ( g_verbose )
	{
	std::cout << "Reading complete." << std::endl << std::endl;
	}

return( result );
}
开发者ID:mistalro,项目名称:openglextensionviewer,代码行数:98,代码来源:extheaderfilesetio.cpp

示例14: nData_records

/**!
 *  The function loads ASCII file header and tries to identify the type of the
 *header.
 *  Possible types are
 *  SPE, PAR or PHS
 *
 *  if none three above identified, returns "undefined" type
 *  it also returns the FileTypeDescriptor, which identifyes the position of the
 *data in correcponding ASCII file
 *  plus characteristics of the data extracted from correspondent data header.
*/
FileTypeDescriptor
FindDetectorsPar::get_ASCII_header(std::string const &fileName,
                                   std::ifstream &data_stream) {
  std::vector<char> BUF(1024);
  FileTypeDescriptor file_descriptor;
  file_descriptor.Type = NumFileTypes; // set the autotype to invalid

  data_stream.open(fileName.c_str(), std::ios_base::in | std::ios_base::binary);
  if (!data_stream.is_open()) {
    g_log.error() << " can not open existing ASCII data file: " << fileName
                  << std::endl;
    throw(Kernel::Exception::FileError(" Can not open existing input data file",
                                       fileName));
  }
  // let's identify the EOL symbol; As the file may have been prepared on
  // different OS, from where you are reading it
  // and no conversion have been performed;
  char symbol;
  data_stream.get(symbol);
  while (symbol > 0x1F) {
    data_stream.get(symbol);
  }
  char EOL;
  if (symbol == 0x0D) { // Win or old Mac file
    data_stream.get(symbol);
    if (symbol == 0x0A) { // Windows file
      EOL = 0x0A;
    } else { // Mac
      EOL = 0x0D;
      data_stream.putback(symbol);
    }
  } else if (symbol == 0x0A) { // unix file.
    EOL = 0x0A;
  } else {
    g_log.error()
        << " Error reading the first row of the input ASCII data file: "
        << fileName << " as it contains unprintable characters\n";
    throw(Kernel::Exception::FileError(" Error reading the first row of the "
                                       "input ASCII data file, as it contains "
                                       "unprintable characters",
                                       fileName));
  }

  file_descriptor.line_end = EOL;
  data_stream.seekg(0, std::ios::beg);

  get_my_line(data_stream, &BUF[0], BUF.size(), EOL);
  if (!data_stream.good()) {
    g_log.error() << " Error reading the first row of the input data file "
                  << fileName << ", It may be bigger then 1024 symbols\n";
    throw(Kernel::Exception::FileError(" Error reading the first row of the "
                                       "input data file, It may be bigger then "
                                       "1024 symbols",
                                       fileName));
  }

  // let's find if there is one or more groups of symbols inside of the buffer;
  int space_to_symbol_change = count_changes(&BUF[0], BUF.size());
  if (space_to_symbol_change >
      1) { // more then one group of symbols in the string, spe file
    int nData_records(0), nData_blocks(0);
    // cppcheck-suppress invalidscanf
    int nDatas = sscanf(&BUF[0], " %d %d ", &nData_records, &nData_blocks);
    file_descriptor.nData_records = (size_t)nData_records;
    file_descriptor.nData_blocks = (size_t)nData_blocks;
    if (nDatas != 2) {
      g_log.error() << " File " << fileName << " iterpreted as SPE but does "
                                               "not have two numbers in the "
                                               "first row\n";
      throw(Kernel::Exception::FileError(" File iterpreted as SPE but does not "
                                         "have two numbers in the first row",
                                         fileName));
    }
    file_descriptor.Type = SPE_type;
    get_my_line(data_stream, &BUF[0], BUF.size(), EOL);
    if (BUF[0] != '#') {
      g_log.error()
          << " File " << fileName
          << "iterpreted as SPE does not have symbol # in the second row\n";
      throw(Kernel::Exception::FileError(
          " File iterpreted as SPE does not have symbol # in the second row",
          fileName));
    }
    file_descriptor.data_start_position =
        data_stream.tellg(); // if it is SPE file then the data begin after the
                             // second line;
  } else {
    file_descriptor.data_start_position =
        data_stream.tellg(); // if it is PHX or PAR file then the data begin
//.........这里部分代码省略.........
开发者ID:spaceyatom,项目名称:mantid,代码行数:101,代码来源:FindDetectorsPar.cpp

示例15: if

// reads in next token from file and matches it to a token type,
// if tokStr is non-NULL then it will be set to the text of the token
MD5Model::TOKEN MD5Model::getNextToken(std::ifstream &fin, std::string *tokStr) {
	skipWhitespace(fin);
	std::string str;

	TOKEN t = TOKEN_INVALID;

	while (!fin.eof()) {
		char c = '\0';
		fin.get(c);

		// single character tokens
		if ('{' == c || '}' == c || '(' == c || ')' == c) {
			// if already reading in a token, treat this as a delimiter
			if (t != TOKEN_INVALID) {
				fin.putback(c);
				if (tokStr != NULL)
					(*tokStr) = str;
			}

			if ('{' == c)
				t = TOKEN_LBRACE;
			if ('}' == c)
				t = TOKEN_RBRACE;
			if ('(' == c)
				t = TOKEN_LPAREN;
			if (')' == c)
				t = TOKEN_RPAREN;

			if (tokStr) {
				(*tokStr) = std::string();
				(*tokStr) += c;
			}
			return t;
		}
		if (isdigit(c)) {
			str += c;
			if (TOKEN_INVALID == t)
				t = TOKEN_INT;
			else if (t != TOKEN_INT && t != TOKEN_FLOAT && t != TOKEN_KEYWORD) {
				std::string msg("MD5Model::getNextToken(): invalid token '");
				msg += str + "'";
				throw Exception(msg);
			}
		}
		if ('-' == c) {
			str += c;
			if (TOKEN_INVALID == t)
				t = TOKEN_INT;
			else {
				std::string msg("MD5Model::getNextToken(): invalid token '");
				msg += str + "'";
				throw Exception(msg);
			}
		}
		if (isalpha(c)) {
			str += c;
			if (TOKEN_INVALID == t)
				t = TOKEN_KEYWORD;
			else if (t != TOKEN_KEYWORD) {
				std::string msg("MD5Model::getNextToken(): invalid token '");
				msg += str + "'";
				throw Exception(msg);
			}
		}
		if ('"' == c) {
			// treat as a delimeter if already reading in a token
			if (t != TOKEN_INVALID) {
				fin.putback(c);
				if (tokStr != NULL)
					(*tokStr) = str;
				return t;
			}
			readString(fin, str);

			if (tokStr != NULL)
				(*tokStr) = str;

			return TOKEN_STRING;
		}
		if ('.' == c) {
			str += c;
			if (t != TOKEN_INT) {
				std::string msg("MD5Model::getNextToken(): invalid token '");
				msg += str + "'";
				throw Exception(msg);
			}
			t = TOKEN_FLOAT;
		}
		if ('/' == c) {
			// treat as a delimeter if already reading in a token
			if (t != TOKEN_INVALID) {
				if (tokStr != NULL)
					(*tokStr) = str;
				return t;
			}

			skipComments(fin);
			skipWhitespace(fin);
//.........这里部分代码省略.........
开发者ID:Jeromecen,项目名称:MD5SkeletalAnimation,代码行数:101,代码来源:MD5Model.cpp


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