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


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

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


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

示例1: if

int
MiscReadCharsAndDoubleFromFile(
  std::ifstream& ifs,
  std::string&   termString,
  double*        termValue,
  bool&          endOfLineAchieved)
{
  int iRC = UQ_OK_RC;
  endOfLineAchieved = false;

  char c = ' ';
  while (c == ' ') {
    ifs.get(c);
    if ((ifs.rdstate() & std::ifstream::failbit)) {
      iRC = UQ_FAILED_READING_FILE_RC;
      break;
    }
  };

  char term[512];
  unsigned int pos = 0;

  if (!iRC) {
    while ((pos < 512) && (c != '\n') && (c != '\0') && (c != ' ')) {
      term[pos++] = c;
      if ((ifs.rdstate() & std::ifstream::failbit)) {
        iRC = UQ_FAILED_READING_FILE_RC;
        break;
      }
      ifs.get(c);
    };
  }

  if (!iRC) {
    if (c == '\n') endOfLineAchieved = true;
    term[pos] = '\0';
    termString = term;
    //std::cout << "Read chars = " << termString << std::endl;
    if (termValue) {
      if (termString == std::string("inf")) {
        *termValue = INFINITY;
      }
      else if (termString == std::string("-inf")) {
        *termValue = -INFINITY;
      }
      else if (termString == std::string("nan")) {
        *termValue = nan("");
      }
      else {
        *termValue = strtod(termString.c_str(),NULL);
      }
    }
  }

  return iRC;
}
开发者ID:brianw525,项目名称:queso,代码行数:56,代码来源:Miscellaneous.C

示例2: readLine

// read a line in headerLine and discards the any remaining characters
static
void readLine(char *headerLine, std::ifstream& infile){
  infile.getline( headerLine, kMaxNameLength );
  // still some characters left on the current line ?
  if ( !infile.eof() && !infile.bad() && infile.rdstate() & std::ios::failbit){
    // clear failbit
    infile.clear(infile.rdstate() & ~std::ios::failbit);
    // discard characters.
    char c;
    while( infile.get(c) && c != '\n');
  }
}
开发者ID:SiccarPoint,项目名称:child,代码行数:13,代码来源:tInputFile.cpp

示例3: in

/**\brief Used by testers.  
 *
 * Not operators because that would conflict
 * with the std:: operators for unsigned ints, alas.
 */
void in(std::ifstream& i, unsigned48_t& res)
{
    /*
     * print "0x........,0x........,0x........"
     */
    union {
       unsigned48_t   seed;
       unsigned short dummy[sizeof(unsigned48_t)/sizeof(unsigned short)];
    } PUN ;

    char             comma = ',';
    unsigned         j=0;

    while( (comma == ',') && 
        (j < sizeof(PUN.dummy)/sizeof(unsigned short)) &&
        (i >>  PUN.dummy[j])
        ) {

            if(i.peek() == ',') i >> comma;
            j++;
    }
    if(j < sizeof(PUN.dummy)/sizeof(unsigned short) ) {
        // This actually sets the badbit:
        i.clear(std::ios::badbit|i.rdstate());
    }
    res = PUN.seed;
}
开发者ID:yaochang,项目名称:shore-mt,代码行数:32,代码来源:rand48.cpp

示例4: loadPoints

	std::vector<Point> loadPoints(std::ifstream &in) {
		std::vector<Point> result;

		for(;;) {
			double x, y;
			in >> x >> y;
			if (in.rdstate()) {
				// break if any error
				break;
			}
			result.push_back(Point(x, y));
		}

		return result;
	}
开发者ID:ARSekkat,项目名称:OpenGazer,代码行数:15,代码来源:utils.cpp

示例5: FileIsNotOkay

Bool_t RegionFileLoader::FileIsNotOkay(std::ifstream& f)
{
    Bool_t notokay = false;
    std::ios::iostate state = f.rdstate();

    if (f.eof())
    {
        notokay = true;
    }
    else if (f.fail())
    {
        std::cerr << std::hex << std::showbase
                << "fstream is corrupted (badbit=" << (state&std::ios_base::badbit)
                << ",failbit=" << (state&std::ios_base::failbit) << ")"
                << std::dec << std::noshowbase
                << std::endl;
        notokay = true;
    }

    return notokay;
}
开发者ID:jrtomps,项目名称:phdwork,代码行数:21,代码来源:RegionIntegratorMultiDim.cpp

示例6: ReadNextLine

bool CParser::ReadNextLine (std::ifstream& FileInput, int& nLineNum, 
			    std::string& szInputString, const int MAXCHARS,
			    const std::string& szComment, bool bLowerCase)
// ---------------------------------------------------------------------------
// Function: reads the next line skipping over the comment lines
//           and converts all alphabets to lower case if requested
// Input:    file istream, line #, string to hold the input line,
//           max. # of characters expected in each input line,
//           comment character(s) at the beginning of a comment line,
//           lowercase conversion option
// Output:   updated values of line # and the string
//           return value is true if successful
//                           false if an error state is encountered
// Restriction: Cannot read a line over 256 characters
// ---------------------------------------------------------------------------
{
  int flag = 0;
  int flag1 =0;
  bool bWhSpc = false;
  int tokenfound = 1;
  const int MAXCH = 1000;
  char szInp[MAXCH];
  char szTemp [MAXCH];
  std::vector<std::string> tokens;

  // enough capacity to read and store?
  if (MAXCHARS > MAXCH)
    return false;

  // comment character(s)
  int nCLen = static_cast<int>(szComment.length());
  // read the line (skip over comment lines)
  for(;;)
    {
      ++nLineNum;
      FileInput.getline (szInp, MAXCHARS);
      //       // end-of-file?
      //       if (FileInput.eof())
      // 	return false;
      if (FileInput.fail())
	FileInput.clear (FileInput.rdstate() & ~std::ios::failbit);
      // unrecoverable error?
      if (FileInput.bad())
	return false;

      // successful read
      szInputString = szInp;
      GetTokens(szInputString, " ", tokens);
      bWhSpc = EatWhiteSpace(szInputString);
      if ((szInputString.substr(0,nCLen) != szComment)&& (bWhSpc ==false)){	   
	szInputString = szInp;
	GetTokens(szInputString, " ", tokens);
	for(int i=0; i< abs(tokens.size()); i++){
	  std::string temptoken = tokens[i];
	  if (temptoken == "&")
	    flag1 = 1;
	}

	//Filter the comment tokens
	//  FilterComment(szInputString, szComment);

	//if "&" is found continue to read the next line      
	std::string szTempString = szInputString;

	// check if line is continued &
	while(flag1 ==1 && tokenfound == 1){	
	  GetTokens(szTempString, " ", tokens);
	  for(int i=1; i<=abs(tokens.size()); i++){
	    std::string temptoken = tokens[i-1];
	    if (temptoken == "&"){
	      tokenfound = 1;
	      flag = 1;
	    }
	    else{
	      if(flag==1)
		flag = 1;//do nothing token already found
	      else
		tokenfound = 0;
	    }
	  }
	  if(tokenfound ==1){
	    ++nLineNum;
	    RemoveToken(szInputString);
	    //- getting more tokens and add to the existing 
	    FileInput.getline (szTemp, MAXCHARS);
	    // end-of-file?
	    if (FileInput.eof())
	      return false;
	    if (FileInput.fail())
	      FileInput.clear (FileInput.rdstate() & ~std::ios::failbit);
	    // unrecoverable error?
	    if (FileInput.bad())
	      return false;
	    // successful read 
	    szTempString = szTemp;
	    FilterComment(szTempString, szComment);
	    szInputString+=" ";
	    szInputString+=szTemp;
	  }
	  else{
//.........这里部分代码省略.........
开发者ID:vibraphone,项目名称:meshkit,代码行数:101,代码来源:parser.cpp


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