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


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

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


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

示例1: determineResourceCount

/**
 * @brief   determine the number of resources (BITMAPs and SOUNDs)
 * @param   rcfile          reference to a open rc file
 * @param   hfile           reference to a open header file
 * @param   rcBitmapCount   reference to the Bitmap counter (rc file)
 * @param   rcSoundCount    reference to the Sound counter  (rc file)
 * @param   hBitmapCount    reference to the Bitmap counter (h file)
 * @param   hSoundCount     reference to the Sound counter  (h file)
 */
void determineResourceCount(ifstream& rcfile, ifstream& hfile,
    int& rcBitmapCount, int& rcSoundCount,
    int& hBitmapCount, int& hSoundCount)
{
    string Line;
    
    // count resources (i.e. BITMAPs and SOUNDs) in rc file
    while (rcfile.good()) {
        getline(rcfile, Line);
        
        if ((int)Line.find("DISCARDABLE") != -1)
        {
            if ((int)Line.find("BITMAP") != -1)
                rcBitmapCount++;
            else if ((int)Line.find("SOUND") != -1)
                rcSoundCount++;
        }
    }
    
    // count resources (i.e. BITMAPs and SOUNDs) in header file
    while (hfile.good()) {
        getline(hfile, Line);
        
        if ((int)Line.find("#define") != -1)
        {
            if ((int)Line.find("BMP_") != -1)
                hBitmapCount++;
            else if ((int)Line.find("SND_") != -1)
                hSoundCount++;
        }
    }
}
开发者ID:Bombermaaan-R,项目名称:bombermaaan-r,代码行数:41,代码来源:ResGen.cpp

示例2: load

//====================================================================
// Load network from file
//====================================================================
bool BPNet::load( ifstream &ist )
{
	if ( !ist.good() )
		return false;
	
	int numLayers	= 0;
	int numNodes	= 0;
	int numLinks	= 0;

	ist >> numLayers;	// num layers
	
	vector<int> layers(numLayers);
	for(int i = 0; i != numLayers; ++i)
		ist >> layers[i];	// number of nodes in each layer

	ist >> numNodes;
	ist >> numLinks;

	// create network structure (nodes and links)
	createNetwork(0, 0, layers);
	
	// load nodes data
	for (i = 0; i != numNodes; ++i)
		_nodes[i]->load(ist);

	// load links data
	for(i = 0; i != numLinks; ++i)
		_links[i]->load(ist);


	if (!ist.good())
		return false;

	return true;
}
开发者ID:gpertzov,项目名称:BPNet,代码行数:38,代码来源:BPNet.cpp

示例3: readGrammar

  static void readGrammar(ifstream& infile, map<string, Definition>& grammar)
  {   
    // Keep parsing until EOF is reached.
    while(infile.good())
    { 
      // Ignore all chars until '{' is reached.
      infile.ignore(numeric_limits<streamsize>::max(), '{');

      // Ignore all chars until '\n' is reached.
      infile.ignore(numeric_limits<streamsize>::max(), '<');

      if(infile.good()) 
      {
        // Beginning of a definition; parse into program.
        Definition myDefinition = Definition(infile);
        
        // Fill map.
        string myNonTerminal = myDefinition.getNonterminal();
        pair<string, Definition> myPair(myNonTerminal, myDefinition);
        grammar.insert(myPair);
      }
    }

    infile.close();
}
开发者ID:charbelZeaiter,项目名称:Sentence-Generator,代码行数:25,代码来源:rsg.cpp

示例4: Error

Meeting::Meeting(ifstream& is, const Participants_t& people) {
    int number_of_participants;
    is >> m_time >> m_topic >> number_of_participants;
    if (!is.good()) {
        throw Error("Invalid data found in file!");
    }

    for (int i = 0; i < number_of_participants; ++i){
        String lastname;

        is >> lastname;
        if (!is.good()) {
            throw Error("Invalid data found in file!");
        }

        Person person(lastname);
        auto iter = people.find(&person);
        if (iter == people.end()) {
            throw Error("Invalid data found in file!");
        }
        else {
            participants.insert(*iter);
        }
    }
}
开发者ID:roudy16,项目名称:enfant,代码行数:25,代码来源:Meeting.cpp

示例5: readPlayerFromBinary

bool readPlayerFromBinary(Player& player, ifstream& input)
{
    assert(input.good());
    Player plr;
    input.read((char*)&plr, sizeof(plr));
    bool result = input.good() && input.gcount() == sizeof(plr);
    if (result) player = plr;
    return result;
}
开发者ID:dianvaltodorov,项目名称:learning-code,代码行数:9,代码来源:Player.cpp

示例6: readModel

bool MlMaximumEntropyModel::readModel(ifstream& ifs)
{
	char buffer[256];
	while (ifs.good())
	{
		ifs.getline(buffer,256);
		if (ifs.gcount()>0 && buffer[0]!='#')
			break;
	}
		
	unsigned int numClasses=0;
	if (sscanf(buffer,"MAXIMUM_ENTROPY %u",&numClasses) != 1)
	{
		cout << "Bad line in model file:" << endl << buffer << endl;
		return false;
	}

	weights_.resize(numClasses);
	for (size_t c=0; c<numClasses; c++)
	{
		ifs.getline(buffer,256);
		unsigned int numWeights=0;
		if (sscanf(buffer,"%u",&numWeights) != 1)
		{
			cout << "Bad line in model file:" << endl << buffer << endl;
			return false;
		}
		weights_[c].resize(numWeights,0.0);
		while (ifs.good())
		{
			ifs.getline(buffer,256);
			if (! strncpy(buffer,"END_",4))
				break;
			if (ifs.gcount() == 0 || buffer[0] != 'F')
				continue;

			size_t index;
			float  weight;
			istringstream iss(buffer+1);
			iss >> index >> weight;
			if (iss.fail())
			{
				if (strlen(buffer)<3)
					continue;

				cout << "Bad line in model file:" << endl << buffer << endl;
				return false;
			}
			if (index>weights_[c].size())
				error("Bad feature index in line: ",buffer);

			weights_[c][index]=weight;
		}
	}
	return true;
}
开发者ID:benpullman,项目名称:mscluster2,代码行数:56,代码来源:mlmaximumentropy.cpp

示例7: bin2str

/**
 * reads char stream to bit stream using previous method
 */
void bin2str(ifstream & ifs,deque<char> & ss)
{
	char aux = 0;
	while(ifs.good())
	{
		aux=ifs.get(); if(!ifs.good()) break;
		string  tmp = ascii2bin(aux);
		ss.insert(ss.end(),tmp.data(),tmp.data()+tmp.length());
	}
}
开发者ID:AhmetHan,项目名称:Huffman-Encoding,代码行数:13,代码来源:huff.cpp

示例8: isAllReady

/// <summary>
/// Checks if all files are in place.
/// </summary>
int isAllReady()
{
	br_file_old = ifstream("DOT_BR_OLD.txt");
	en_file_old = ifstream("DOT_EN_OLD.txt");

	if (!br_file_old.good() || !en_file_old.good())
	{
		cout << "ERROR: Files are not in place!" << endl;
		cout << "Please put DOT_BR_OLD.txt and DOT_EN_OLD.txt in this same folder!" << endl;
		return false;
	}

	return true;
}
开发者ID:ScummBR,项目名称:DOT_Translating_Tool,代码行数:17,代码来源:main.cpp

示例9: createC1

int createC1(char *inpFileName, vector<int>& rowVec, vector<short>& colVec, int& noOfTrans, set<int>& itemsSet, map<int,int>& C1 ){

	inpFileStream.open(inpFileName);
	if(!inpFileStream.good()){
		inpFileStream.close();
		cout<<"While Generating C1"<<endl;
		cout<<"Error in opening datafile or datafile doesn't exists"<<endl;
		return 1;
	}
	
	vector<int> dataLine;
	u_int dataLen;
	map<int,int>::iterator C1Iter;
	while(readLineFromFile(dataLine, dataLen)){
		if(dataLen){
			rowVec.push_back(dataLen + rowVec[noOfTrans]);
			++noOfTrans;
		}
		for(int i = 0; i < dataLen; ++i){
			colVec.push_back((short)dataLine[i]);
			itemsSet.insert(dataLine[i]);
			if((C1Iter = C1.find(dataLine[i])) != C1.end()){
				++((C1Iter)->second);
			}
			else
			++C1[dataLine[i]];
		}
	}	
	inpFileStream.close();
	
	return 0;
}
开发者ID:1098896743,项目名称:Improved-Apriori-Algorithm,代码行数:32,代码来源:common.cpp

示例10: readInt

bool Serializer::readInt(ifstream &infile, int &ret) {
	unsigned char buf[4];
	infile.read((char *)buf, 4);
	if (!infile.good())
		return false;

	// Integer is stored in big-endian format

	// See if it's positive or negative. If the first bit is 1 then it's negative
	bool neg = ((buf[0] >> 7) == 1);
	buf[0] = buf[0] & 0x7f;

	int newRet = 0;
	newRet += buf[3] * ONE_SHIFT_ZERO;
	newRet += buf[2] * ONE_SHIFT_ONE;
	newRet += buf[1] * ONE_SHIFT_TWO;
	newRet += buf[0] * ONE_SHIFT_THREE;

	if (neg)
		newRet = -newRet;

	ret = newRet;

	return true;
}
开发者ID:eperiod-software,项目名称:metal-trainer,代码行数:25,代码来源:Serializer.cpp

示例11: open

void GrowToolbar::open( ifstream& fp)
{
  int		type;
  int 		end_found = 0;
  char		dummy[40];

  for (;;)
  {
    if ( !fp.good()) {
      fp.clear();
      fp.getline( dummy, sizeof(dummy));
      printf( "** Read error GrowToolbar: \"%d %s\"\n", type, dummy);      
    }

    fp >> type;
    switch( type) {
      case glow_eSave_GrowToolbar: break;
      case glow_eSave_GrowToolbar_grownode_part: 
        GrowNode::open( fp);
        break;
	// case glow_eSave_GrowToolbar_nc: 
        // nc = new GlowNodeGroup( ctx, n_name);
        // nc->open( fp);
        // break;
      case glow_eSave_End: end_found = 1; break;
      default:
        cout << "GrowToolbar:open syntax error" << endl;
        fp.getline( dummy, sizeof(dummy));
    }
    if ( end_found)
      break;
  }
}
开发者ID:ManfredHerrmann,项目名称:proview,代码行数:33,代码来源:glow_growtoolbar.cpp

示例12: _main

int _main() {

	while (dictin.good()) {
		string word;
		dictin >> word;
		dict.push_back(word);
	}

	char charNumMapping[][3] = { { ' ', ' ', ' ' }, { ' ', ' ', ' ' }, { 'A',
			'B', 'C' }, { 'D', 'E', 'F' }, { 'G', 'H', 'I' },
			{ 'J', 'K', 'L' }, { 'M', 'N', 'O' }, { 'P', 'R', 'S' }, { 'T',
					'U', 'V' }, { 'W', 'X', 'Y' } };

	string num;
	fin >> num;

	found = false;

	printAllCombinations(num, charNumMapping);

	if (!found) {
		fout << "NONE" << endl;
	}

	return 0;
}
开发者ID:KareemErgawy,项目名称:USACOSolutions,代码行数:26,代码来源:Main.cpp

示例13: open

void GlowCustomColors::open( ifstream& fp)
{
  int		type;
  int 		end_found = 0;
  char		dummy[40];
  int 		csize = 0;

  for (;;)
  {
    if ( !fp.good()) {
      fp.clear();
      fp.getline( dummy, sizeof(dummy));
      printf( "** Read error GlowCustomColors: \"%d %s\"\n", type, dummy);      
    }

    fp >> type;
    switch( type) {
      case glow_eSave_CustomColors: break;
      case glow_eSave_CustomColors_colortheme_lightness: fp >> colortheme_lightness; break;
      case glow_eSave_CustomColors_is_default_colortheme: fp >> is_default_colortheme; break;
      case glow_eSave_CustomColors_colors_size: fp >> csize; break;
      case glow_eSave_CustomColors_colors:
	for ( int i = 0; i < csize; i++) {
	  fp >> colors[i][0]; fp >> colors[i][1]; fp  >> colors[i][2];
	}
	break;
      case glow_eSave_End: end_found = 1; break;
      default:
        cout << "GlowCustomColors:open syntax error" << endl;
        fp.getline( dummy, sizeof(dummy));
    }
    if ( end_found)
      break;
  }
}
开发者ID:ManfredHerrmann,项目名称:proview,代码行数:35,代码来源:glow_customcolors.cpp

示例14: getSize

//private function called by load(). Passed parameter is the file (ifstream) as imported by load()
//returns integer of number of columns and rows. Returns negative value if invalid grid
int Grid::getSize(ifstream& sourceFile)
{
	int puzSize=0, rowLength;
	string tempString;

	//count how many rows of text
	while(sourceFile.good()){
		getline(sourceFile, tempString);
		puzSize++;
	}
	
	sourceFile.seekg(0,ios::beg);	//move cursor back to beginning
	sourceFile.clear();				//clear error flags
	
	//go through each line again, checking there are the right number of columns in each row
	while(!sourceFile.eof()){
		getline(sourceFile, tempString);
		rowLength = tempString.length();
		if(rowLength!=puzSize){ //if # of columns does not match # of rows
			cout << "Wrong number of columns in this row: "<<tempString<<endl;
			return -1; //if there is a problem, return negative number (and exit)
		}
	}
	sourceFile.seekg(0,ios::beg);	//when finished, make sure to leave cursor at beginning of file
	sourceFile.clear();				//clear error flags
	return puzSize;
}
开发者ID:teekers,项目名称:crossword-generator,代码行数:29,代码来源:Grid.cpp

示例15:

	BitString::BitString(ifstream & input) {
		assert(input.good());
		input.read((char*)&length,sizeof(size_t));
		input.read((char*)&uintLength,sizeof(size_t));
		data = new uint[uintLength];
		input.read((char*)data,uintLength*sizeof(uint));
	}
开发者ID:rkonow,项目名称:libcds,代码行数:7,代码来源:libcdsBitString.cpp


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