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


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

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


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

示例1: openInput

int openInput(ifstream& opIn,string unsortfile){
     
     
     opIn.open(unsortfile.c_str());
     
     if(opIn.fail()){
                     
     cout<<unsortfile<<" does not exist.\n";                               
     opIn.close();
     return 0;
    
     }
     
     else return 1;
     }
开发者ID:Yen168,项目名称:algorithms-computers-and-programming-cpp,代码行数:15,代码来源:P8_1.cpp

示例2: encrypt

//*****************************************************
//Encrypt function uses the virtual transform         *
//member function to transform individual characters. *
//***************************************************** 
void Encryption::encrypt()
{
  char ch;
  char transCh;
  inFile.get(ch);
  while (!inFile.fail())
    {
      transCh = transform(ch);
      outFile.put(transCh);
      inFile.get(ch);
    }
    
    inFile.clear();
    inFile.seekg(0);
}
开发者ID:Merfoo,项目名称:CS-162,代码行数:19,代码来源:main.cpp

示例3: OpenFiles

void OpenFiles (ifstream &Inp, ofstream &Out)
{
   char Fname[255];

   do
   {
      cout << "Input file name: " << flush;
      cin.getline(Fname, 255);
      Inp.clear();
	  Inp.open(Fname, ios::in); //Inp.open(Fname, ios::in|ios::nocreate);
	  if (Inp.fail())
         cout << "Failed to open " << Fname << " --- try again\n";
   } while ( Inp.fail() );

   do
   {
      cout << "Output file name:  " << flush;
      cin.getline(Fname, 255);
      Out.clear();
      Out.open(Fname);
      if (Out.fail())
         cout << "Failed to open hw2output.txt  " << Fname << " --- try again\n";
   } while ( Out.fail() );
}
开发者ID:ericfode,项目名称:CSCD305-1,代码行数:24,代码来源:hw2tester.cpp

示例4: openInFile

/********************************
** Function: void openInFile(ifstream &fin, string str);
** Description: Open the file and check for errors
**  throw exception if file open fails
**
**
** Parameters: ifstream fin is the file handle
**  string str is the name of the file to open
**
** pre-conditions: fin has been declared, str is a valid file name
** post-conditions: file opened and checked for errors in opening
********************************/
void openInFile(ifstream &fin, char str[])
{
     // can't open empty names
     if (str[1] == '\0') throw (-1);

     // attempt to open file
     fin.open(str);
     if (fin.fail())
     {
          cout << "SOMETHING WENT TERRIBLY WRONG! FAILED TO OPEN INPUT FILE"
               << endl;
          throw(-1);
     }
     return;
}
开发者ID:huffakco,项目名称:CS325Group6Project2,代码行数:27,代码来源:generateTest.cpp

示例5: InputNumScores

int InputNumScores(ifstream& input)
{
  int numScores;
  string fileName = "c";
  cout << "What file will you be reading from, sir or madame?\n";
  cin >> fileName;
  input.open(fileName.c_str());
  if (input.fail())
    {
      cout << "File read error.\n";
      exit(1);
    }
  input >> numScores;
  return numScores;
}
开发者ID:EricRobertBrewer,项目名称:SonomaState,代码行数:15,代码来源:Lab8b.cpp

示例6: connectFileAndGetNumLines

//  Pre Condition:  name is the file that will be attempted to open with ifs
// Post Condition:  Returns the number of lines in the file, or -1 for fail to open
//					closes ifs
int connectFileAndGetNumLines(ifstream &ifs, string name) {
	ifs.open(name);
	int numLines = 0;
	string trash;

	// if open fails return -1
	if (ifs.fail())
		return -1;
	else
		while (getline(ifs, trash))
			numLines++;

	ifs.close();

	return numLines;
}
开发者ID:joshguerra,项目名称:CIT-237-01HB,代码行数:19,代码来源:Lab1B-Part3-JGuerra.cpp

示例7: ReadScores

void ReadScores(ifstream &in1, Vector<int> &scores) {
    while (true) {
        int x;
        in1 >> x;
        if (in1.fail()) {
            break; // no more lines to read
        }
        cout << x << endl;
        //Input can haveletters, punctuation or whitespace, but only integers between 0 and 99 are accepted.
        
        if (x >= 0 && x <= 99) {
            scores[x / 10] += 1;
        }
        
    } 
}
开发者ID:vincemansel,项目名称:Cpp_Daily_Code,代码行数:16,代码来源:histogram.cpp

示例8: getEdges

vector<Edge> getEdges(ifstream & input){
    vector<Edge> edges;
    while(true){
        int start;
        int end;
        input>>start;
        input>>end;
        if(input.fail())
            break;
        Edge currEdge;
        currEdge.start=start;
        currEdge.end=end;
        edges.push_back(currEdge);
    }
    return edges;
}
开发者ID:viendiesel,项目名称:CS106LHW1,代码行数:16,代码来源:main.cpp

示例9: openFiles

void openFiles(char *argv[], ifstream &in, ofstream &out)
{
	in.open(argv[1]);
	if (in.fail())
	{
		cerr << endl << "*** ERROR: Can not open " << argv[1] << " for input." << endl;
		exit(0);
	}

	out.open(argv[2]);
	if (out.fail())
	{
		cerr << endl << "*** ERROR: Can not open " << argv[2] << " for output." << endl;
		exit(0);
	}
}
开发者ID:ZenithIO89,项目名称:myfantastic-stuff,代码行数:16,代码来源:C10pp09.cpp

示例10: reverse

void reverse(ifstream &filein){
	string buffer;
	filein >> buffer;

	if(filein.fail()){
		return;
	}
	else{
		reverse(filein);

		cout<<buffer<<endl;
	}
	

return;
}
开发者ID:Liao062,项目名称:hw_liao062,代码行数:16,代码来源:hw1q5.cpp

示例11: inputFileValCounter

void inputFileValCounter(ifstream& in, int numVal[])
{
	int valueCount = 0;
	int value;

	while (!in.eof())
	{
		in >> value;
		if (!in.fail())
			valueCount++;
	}

	numVal[0] = valueCount;											//stores count for later use

	cout << "I counted " << valueCount << " values.\n" << endl;
	
}
开发者ID:CodyCamp,项目名称:HomeworkAssignments,代码行数:17,代码来源:NumberFileAnalyzer.cpp

示例12: CountMap

void CountMap(ifstream & instr) {
	Map<string, int> myMap;
	string nxtword;

	while (true) {
		instr >> nxtword;
		if (instr.fail()) break;
		else {
			if (myMap.containsKey(nxtword)) {
				int count = myMap.get(nxtword);
				myMap[nxtword] = count + 1;
			} else
				myMap[nxtword] = 1;
		}
	}
	PrintMap(myMap);
}
开发者ID:poepye,项目名称:cs106b_snippets,代码行数:17,代码来源:map.cpp

示例13: ReadScores1

void ReadScores1(ifstream &in1, Vector<int> &scores) {
    while (true) {
        string line;
        getline(in1, line);
    
        if (in1.fail()) {
            break; // no more lines to read
        }
        cout << line << endl;
        //Input line must be well form. Only digits. No letters, punctuation or whitespace.
        int x = StringToInteger(line);
        
        if (x >= 0 && x <= 99) {
            scores[x / 10] += 1;
        }
        
    } 
}
开发者ID:vincemansel,项目名称:Cpp_Daily_Code,代码行数:18,代码来源:histogram.cpp

示例14: CountNonblankLines

int CountNonblankLines( ifstream& ifg )
{
	char buf[400]="";

	streampos pos = ifg.tellg();
	int nLines = 0;

	ifg.getline( buf, ELEMENTS(buf) );
	do{
		trim(buf);
		if( buf[0]!=NULL )nLines++;

		ifg.getline( buf, ELEMENTS(buf) );
	}while( !ifg.fail() );
	ifg.clear();
	ifg.seekg( pos, ios::beg );
	return nLines;
}
开发者ID:EISALab,项目名称:AMGAgroundwater,代码行数:18,代码来源:stdfor_c.cpp

示例15: check_files

void check_files( ifstream &file )
{
    char buffer[ 129 ];
    char file_name[ 81 ];
    char revision[ 20 ];
    unsigned long crc;

    for ( ; ; ) {
        file.getline( buffer, 129 );
        if ( file.fail() || file.eof() )
            return;
        if ( buffer[ 0 ] != ';' && buffer[ 0 ] != ' ' && buffer[ 0 ] != '\0' ) {
            istrstream s( buffer );
            s >> file_name;
            s >> hex >> crc;
            s >> revision;
            check_file( file_name, crc, revision );
        } else
开发者ID:softwarepublico,项目名称:lightbase,代码行数:18,代码来源:CHECKREV.CPP


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