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


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

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


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

示例1: LoadPpm

TypedImage LoadPpm(std::ifstream& bFile)
{
    // Parse header
    std::string ppm_type = "";
    int num_colors = 0;
    int w = 0;
    int h = 0;

    bFile >> ppm_type;
    PpmConsumeWhitespaceAndComments(bFile);
    bFile >> w;
    PpmConsumeWhitespaceAndComments(bFile);
    bFile >> h;
    PpmConsumeWhitespaceAndComments(bFile);
    bFile >> num_colors;
    bFile.ignore(1,'\n');

    if(!bFile.fail() && w > 0 && h > 0) {
        TypedImage img(w, h, PpmFormat(ppm_type, num_colors) );

        // Read in data
        for(size_t r=0; r<img.h; ++r) {
            bFile.read( (char*)img.ptr + r*img.pitch, img.pitch );
        }
        if(!bFile.fail()) {
            return img;
        }
    }

    throw std::runtime_error("Unable to load PPM file.");
}
开发者ID:amarburg,项目名称:Pangolin,代码行数:31,代码来源:image_io.cpp

示例2: die_if_unable_to_open_file

void die_if_unable_to_open_file(std::ifstream& in, const std::string& fn)
{
        if (in.fail()) {
        auto msg = "Failed to open file `" + fn + "'.";
        PCSH_ENFORCE_MSG(!in.fail(), msg.c_str());
    }
}
开发者ID:akalsi87,项目名称:pcsh,代码行数:7,代码来源:main.cpp

示例3: read

void OpenMTP_binary_header::read( std::ifstream &file )
{
  unsigned char *pnt;

  memset(header, 0, BUFLEN);

  file.read((char *) header, BINARY_HEADER_FIRST_SECTION_LENGTH);
  if (file.fail( ))
  {
    std::cerr << "Read error : BINARY Header, first section." << std::endl;
    throw;
  }

  pnt = header + BINARY_HEADER_FIRST_SECTION_LENGTH;

  if (is_rectified())
  {
    file.seekg(BINARY_HEADER_SECOND_SECTION_LENGTH, ios::cur);
    if (file.fail( ))
    {
      std::cerr << "Read error : BINARY Header, second section" << std::endl;
      throw;
    }
  }
  else
  {
    file.read((char *) pnt, BINARY_HEADER_SECOND_SECTION_LENGTH);
    if (file.fail( ))
    {
      std::cerr << "Read error : BINARY Header, second section" << std::endl;
      throw;
    }
  }

  pnt = pnt + BINARY_HEADER_SECOND_SECTION_LENGTH;
  if (is_visible_composite())
  {
    file.read((char *) pnt, BINARY_HEADER_THIRD_SECTION_VIS_CMP_LENGTH);
    if (file.fail( ))
    {
      std::cerr << "Read error : BINARY Header, third section" << std::endl;
      throw;
    }
  }
  else
  {
    file.read((char *) pnt, BINARY_HEADER_THIRD_SECTION_NORMAL_LEGTH);
    if (file.fail( ))
    {
      std::cerr << "Read error : BINARY Header, third section" << std::endl;
      throw;
    }
  }

  return;
}
开发者ID:ARPA-SIMC,项目名称:meteosatlib,代码行数:56,代码来源:OpenMTP_binary_header.cpp

示例4: angleBracket

//the case if encounter a angle bracket "["
void MDparser::angleBracket(std::string& tobeStored, bool& readyToStore, std::ifstream& myinput, myset<std::string>& allWords, myset<std::string>& allLinks){
	string buffer("");

    char letter=(char)myinput.get();
    while(letter!=']'&& !myinput.fail()){
      buffer=buffer+letter;
      letter=(char)myinput.get();
   }
   buffer+="]";
   //parsing,change bool varibale to false
   for (int i=0;i<(int)buffer.size();i++){
   		letter=buffer[i];
   		if(isLetter(letter)){
   			readyToStore=true;
   			tobeStored+=letter;
   		}
   		else if(!isLetter(letter)&&readyToStore){
   			allWords.insert(tobeStored);
   			tobeStored="";
   			readyToStore=false;
   		}
   		else if(!isLetter(letter)&&!readyToStore){
   			//donothing
   		}
   }

   if(!myinput.fail()){
   	   letter=(char)myinput.get(); //get the next letter after']'
		if(letter=='('){
			buffer="";
			letter=(char)myinput.get();
			while(letter!=')'){
				buffer+=letter;
				letter=(char)myinput.get();
			}
			ifstream my_input(buffer.c_str());
			if(!my_input.fail()){
				allLinks.insert(buffer);				
			}
			my_input.close();
			buffer="";
			readyToStore=false;
		}
		else{
			if(isLetter(letter)){
				readyToStore=true;
				tobeStored+=letter;
			}
			else{
				readyToStore=false;
			}
		}
   }
}
开发者ID:sean1996,项目名称:SearchEngine-PageRank,代码行数:55,代码来源:MDparser.cpp

示例5: CheckAndCompareFileString

bool TUtilities::CheckAndCompareFileString(std::ifstream &InFile, AnsiString InString)
//Reads the next item and checks it as a string value up to either the '\0' delimiter
//if there is one, in which case the '\0' is extracted but nothing more, or up to the next '\n',
//in which case the '\n' is extracted.  There may or may not be a '\n' at the start, and if there
//is it is ignored (only one is ignored, a second one is treated as a delimiter).
//The item is then compared with InString and fails if different.
{
char TempChar;
char *Buffer = new char[10000];
int Count = 0;
InFile.get(TempChar);//may or may not be '\n'
if(InFile.fail())
    {
    delete Buffer;
    return false;
    }
if(TempChar == '\n')
    {
    InFile.get(TempChar);//get the next one if first was '\n'
    if(InFile.fail())
        {
        delete Buffer;
        return false;
        }
    }
while((TempChar != '\0') && (TempChar != '\n'))
    {
    if((TempChar < 32) && (TempChar >= 0))
        {
        delete Buffer;
        return false;
        }
    Buffer[Count] = TempChar;
    Count++;
    InFile.get(TempChar);
    if(InFile.fail())
        {
        delete Buffer;
        return false;
        }
    }
Buffer[Count] = '\0';
Count++;
Buffer[Count] = '\n';
Count++;
if(AnsiString(Buffer) != InString)
    {
    delete Buffer;
    return false;
    }
delete Buffer;
return true;
}
开发者ID:jagercode,项目名称:railway-dot-exe,代码行数:53,代码来源:Utilities.cpp

示例6: SkipHeaderLines

 /**
  * This helper method just moves forward the two file pointers to skip some header lines.
  * @param numLinesToSkip  The number of header lines to skip
  */
 void SkipHeaderLines(unsigned numLinesToSkip)
 {
     if (!mCalledCollectively || PetscTools::AmMaster())
     {
         for (unsigned line_number=0; line_number<numLinesToSkip; line_number++)
         {
             char buffer[1024];
             mpFile1->getline(buffer, 1024);
             mpFile2->getline(buffer, 1024);
             TS_ASSERT(!mpFile1->fail()); // Here we assume there are at least "ignoreFirstFewLines" lines...
             TS_ASSERT(!mpFile2->fail()); // ...and that they are lines of no more than 1024 characters
             mLineNum++;
         }
     }
 }
开发者ID:Chaste,项目名称:Chaste,代码行数:19,代码来源:AbstractFileComparison.hpp

示例7: CheckFileInt

//---------------------------------------------------------------------------
bool TUtilities::CheckFileInt(std::ifstream &InFile, int Lowest, int Highest)
//no need to worry about leading '\n' characters as the skipws (skip white space) flag is
//set automatically
{
AnsiString IntString;
if(!CheckAndReadFileString(InFile, IntString)) return false;
if(InFile.fail()) return false;
if(IntString == "") return false;
for(int x=1;x<=IntString.Length();x++)
    {
    bool CharacterOK = false;
    if((x == 1) && (IntString[x] == '-'))
        {
        CharacterOK = true;
        }
    else if((IntString[x] >= '0') && (IntString[x] <= '9'))
        {
        CharacterOK = true;
        }
    if(!CharacterOK) return false;
    }
int TempInt = IntString.ToInt();
if((TempInt < Lowest) || (TempInt > Highest))
    {
    return false;
    }
return true;
}
开发者ID:jagercode,项目名称:railway-dot-exe,代码行数:29,代码来源:Utilities.cpp

示例8: openInputFile

void openInputFile(std::ifstream& s, std::string path){
  s.open(path);
  if(s.fail()){
    std::cerr << "Failure opening file \"" << path << "\" for input." << std::endl;
    exit(0);
  }
}
开发者ID:bfisch02,项目名称:csax_cpp,代码行数:7,代码来源:io.cpp

示例9: read

bool File::read(std::ifstream& stream)
{
  CwdGuard cg(physical_dir_);
  stream.open(ACE_TEXT_ALWAYS_CHAR(physical_file_.c_str()),
              ios::binary | ios::in);
  return !stream.bad() && !stream.fail();
}
开发者ID:binary42,项目名称:OCI,代码行数:7,代码来源:FileSystemStorage.cpp

示例10: ReadWorldTagData

void ReadWorldTagData( std::ifstream &inStream, UString &tag, UString &data )
{
	char temp[4096];
	tag = "o---o";
	data = "o---o";
	while( !inStream.eof() && !inStream.fail() )
	{
		inStream.getline( temp, 4096 );
		UString sLine( temp );
		sLine = sLine.removeComment().stripWhiteSpace();
		if( !sLine.empty() )
		{
			if( sLine != "o---o" )
			{
				if( sLine.sectionCount( "=" ) == 1 )
				{
					tag		= sLine.section( "=", 0, 0 ).stripWhiteSpace();
					data	= sLine.section( "=", 1 ).stripWhiteSpace();
					break;
				}
			}
			else
				break;
		}
	}
}
开发者ID:bholtsclaw,项目名称:uox3,代码行数:26,代码来源:fileio.cpp

示例11: readElementsFromStream

bool TetGenInterface::readElementsFromStream(std::ifstream &ins)
{
	std::string line;
	getline (ins, line);
	size_t pos_beg (line.find_first_not_of(" "));
	size_t n_tets, n_nodes_per_tet;
	bool region_attributes;
	bool not_read_header (true);

	while (!ins.fail() && not_read_header)
	{
		line = line.substr(pos_beg);
		if (line.compare(0,1,"#") == 0)
		{
			// this line is a comment - skip
			getline (ins, line);
			pos_beg = line.find_first_not_of(" ");
		}
		else
			// read header line
			not_read_header = !parseElementsFileHeader(line,
			                                           n_tets,
			                                           n_nodes_per_tet,
			                                           region_attributes);
	}
	if (not_read_header)
		return false;
	if (!parseElements(ins, n_tets, n_nodes_per_tet, region_attributes))
		return false;

	return true;
}
开发者ID:wolf-pf,项目名称:ogs_kb1,代码行数:32,代码来源:TetGenInterface.cpp

示例12: getNextLine

static int getNextLine(void)
{
	int i;
	char *p;
  
	nBuffer = 0;
	nTokenStart = -1;
	nTokenNextStart = 0;
	eof = false;

	std::getline(inputFile, buffer);
	if (inputFile.eof())
	{
		eof = true;
		return 1;
	}
	if (inputFile.fail())
	{
		return -1;
	}

	buffer += "\n";
	std::replace(buffer.begin(), buffer.end(), '\t', ' ');

	fileLineMap[currentFileName].push_back(buffer);
	nRow += 1;
	lBuffer = buffer.length();

	return 0;
}
开发者ID:SavourySnaX,项目名称:EDL,代码行数:30,代码来源:main.cpp

示例13: loadImpulses

void CollisionHandler::loadImpulses(std::vector<CollisionInfo> &impulses, std::ifstream &ifs)
{
  impulses.clear();
  int numimpulses=0;
  ifs.read((char *)&numimpulses, sizeof(int));
  for(int i=0; i<numimpulses; i++)
    {
      CollisionInfo::collisiontype type;
      ifs.read((char *)&type, sizeof(CollisionInfo::collisiontype));
      int idx1, idx2;
      ifs.read((char *)&idx1, sizeof(int));
      ifs.read((char *)&idx2, sizeof(int));
      VectorXs n(2);
      ifs.read((char *)n.data(), n.size()*sizeof(scalar));
      double time;
      ifs.read((char *)&time, sizeof(double));
      impulses.push_back(CollisionInfo(type, idx1, idx2, n, time));
    }

  if( ifs.fail() )
    {
      std::cout << outputmod::startred << "Error while trying to deserialize time step impulses. Exiting." << std::endl;
      exit(1);
    }
}
开发者ID:js4768,项目名称:4167T2M1,代码行数:25,代码来源:CollisionHandler.cpp

示例14: LoadDataFromFile

void RegionFileLoader::LoadDataFromFile(std::ifstream &file)
{
    if (file.fail())
    {
        std::cerr << "Error <RegionFileLoader::LoadDataFromFile> File is unreadable" <<  std::endl;
        return;
    }

    Double_t sa;
    std::string aline;
    std::stringstream ss;
    while(1)
    {
        std::getline(file,aline);
        if ( FileIsNotOkay(file) )
            break;
        else if ( LineShouldBeSkipped(aline) )
            continue;
        else if ( BeginningOfRegions(aline) )
        {
//            std::cout << aline << std::endl;
            Regions regions = ReadRegions(file);
            if (regions.size()>0)
                fTheRegions.push_back(regions);
        }
    }

    file.close();

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

示例15: readValue

		bool readValue(std::ifstream& str, std::string key, T& out_value)
		{
			try
			{
				if (!goToMarker(str, key) || str.eof() || str.fail())
					return false;
				str >> out_value;
				if (str.eof() || str.fail())
					return false;
			}
			catch (...)
			{
				return false;
			}
			return true;
		}
开发者ID:Kosyl,项目名称:H265Lib,代码行数:16,代码来源:FileIO.cpp


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