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


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

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


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

示例1: read

void Profile::read(std::ifstream& fin) {
	std::string line;
	while (getline(fin, line)) {
		if (line.substr(0, 8) == "#Profile") break;
	}
	assert(fin.good());

	int tmp_prolen, tmp_ncodes;
	fin>> tmp_prolen>> tmp_ncodes;
	assert(fin.good() && (tmp_ncodes == NCODES));

	if (tmp_prolen != proLen) {
		delete[] p;
		proLen = tmp_prolen;
		size = proLen * NCODES * NCODES;
		p = new double[proLen][NCODES][NCODES];
		memset(p, 0, sizeof(double) * size);
	}
	
	for (int i = 0; i < proLen; ++i)
		for (int j = 0; j < NCODES; ++j)
			for (int k = 0; k < NCODES; ++k)
	assert(fin>> p[i][j][k]);

	getline(fin, line);
}
开发者ID:pachterlab,项目名称:PROBer,代码行数:26,代码来源:Profile.cpp

示例2: loadFromStream

bool BSAFolderRecord::loadFromStream(std::ifstream& in_File)
{
  if (!in_File.good())
  {
    std::cout << "BSAFolderRecord::loadFromStream: Error: bad stream given!\n";
    return false;
  }
  //read folder record's stuff
  in_File.read((char*) &nameHash, sizeof(BSAHash));
  if (!in_File.good())
  {
    std::cout << "BSAFolderRecord::loadFromStream: Error: could not read hash!\n";
    return false;
  }
  //rest of it
  in_File.read((char*) &count, 4);
  in_File.read((char*) &offset, 4);
  if (!in_File.good())
  {
    std::cout << "BSAFolderRecord::loadFromStream: Error while reading data!\n";
    return false;
  }
  //all's well
  return true;
}
开发者ID:Thoronador,项目名称:morrowtools,代码行数:25,代码来源:BSAFolderRecord.cpp

示例3: ReadOneSentence

bool LccrFeaturizer::ReadOneSentence(std::ifstream &src,
                                     std::vector<std::string> &sentence) {
  if (!src.good()) {
    LOG(INFO) << "stream in bad state";
    return false;
  }

  sentence.clear();
  std::string line;

  std::getline(src, line);
  boost::algorithm::trim(line);
  while (src.good() && (line.size() < 1)) {
    std::getline(src, line);
    boost::algorithm::trim(line);
  }

  if ((!src.good()) && (!src.eof())) {
    LOG(FATAL) << "error when read files";
    return false;
  }

  while (src.good() && line.size() > 0) {
    sentence.push_back(line);
    std::getline(src, line);
    boost::algorithm::trim(line);
  }

  return true;
}
开发者ID:lacozhang,项目名称:numopt,代码行数:30,代码来源:lccrfeaturizer.cpp

示例4: ParseFromFStream

		bool XTextureFileName::ParseFromFStream(std::ifstream& in)
		{
			std::streampos pos;
			char separator;

			if (!in.good())
			{
				return false;
			}

			in.clear();
			pos = in.tellg();

			if (!FileName.ParseFromFStream(in))
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			in >> separator;

			if (!in.good() || separator != ';')
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			return true;
		}
开发者ID:SaulHP91,项目名称:DIYlib,代码行数:31,代码来源:xTextureFileName.cpp

示例5: Nanoparticle

CircularNanoparticle::CircularNanoparticle(std::ifstream & stream) : Nanoparticle(stream, Nanoparticle::CIRCLE)
{
	/* FORMAT
	*  <parent_data><mRadius><mBoundary>
	*
	*/

	//we not set badState here as parent constructor may of set it to bad

	stream.read( (char*) &mRadius,sizeof(int));

	if(!stream.good())
	{
		cerr << "Error: Couldn't create CircularNanoparticle. Failed to read mRadius" << endl;
		badState=true;
	}

	stream.read( (char*) &mBoundary,sizeof(enum boundary));

	if(!stream.good())
	{
		cerr << "Error: Couldn't create CircularNanoparticle. Failed to read mBoundary" << endl;
		badState=true;
	}

}
开发者ID:delcypher,项目名称:lc,代码行数:26,代码来源:circle.cpp

示例6: ParseFromFStream

		bool XAnimationKey::ParseFromFStream(std::ifstream& in)
		{
			std::streampos pos;
			char separator;

			if (!in.good())
			{
				return false;
			}

			in.clear();
			pos = in.tellg();

			if (!KeyType.ParseFromFStream(in))
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			in >> separator;
			if (!in.good() || separator != ';')
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			if (!NKeys.ParseFromFStream(in))
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			in >> separator;
			if (!in.good() || separator != ';')
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			if (!Keys.ParseFromFStream(in, NKeys))
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			in >> separator;
			if (!in.good() || separator != ';')
			{
				in.clear();
				in.seekg(pos);
				return false;
			}

			return true;
		}
开发者ID:SaulHP91,项目名称:DIYlib,代码行数:60,代码来源:xAnimationKey.cpp

示例7: getVar

std::string CppLogger::getVar(std::ifstream& file)
{
	std::string result = "";

	while (file.good())
	{
		char c = file.get();
		if (c == '=' || c == '\n')
		{
			break;
		}
		else if (c == '#')
		{
			while (file.good() && file.get() != '\n')
			{
			}
			break;
		}
		else if (c == ' ')
		{
			continue;
		}

		result += c;
	}

	return result;
}
开发者ID:skoczo,项目名称:CppLogger,代码行数:28,代码来源:CppLogger.cpp

示例8: getNextWord

void getNextWord(std::ifstream& inFile, std::string& token, std::string tokenizer, int64_t endOffSet)
{
   token.clear();
   char byte[1];

  while(inFile.good())
  {
     if(inFile.tellg() >= endOffSet)
       return;

     byte[0] =inFile.peek();
     if(byte[0]=='\n' || byte[0] == tokenizer.c_str()[0]){
       inFile.get();
     }else{
       break;
     }
  }


  while(inFile.good()){
   byte[0] = inFile.get();   
   if(byte[0]=='\n' || byte[0] == tokenizer.c_str()[0]){
     return;
   }
    token.append(byte,1);
   }
}
开发者ID:innosam,项目名称:beehive,代码行数:27,代码来源:MapReduce.cpp

示例9: loadGlobalSerializationMetadata

srzMetaDataStruct loadGlobalSerializationMetadata(std::ifstream& f) {

	srzMetaDataStruct md;

	// isk version
	f.read((char *) &(md.iskVersion), sizeof(int));
	if (!f.good()) {
		cerr << "ERROR bad file while reading isk version" << endl;
		return md;
	}

	// binding language
	f.read((char *) &(md.bindingLang), sizeof(int));
	if (!f.good()) {
		cerr << "ERROR bad file while reading lang" << endl;
		return md;
	}

    // trial or full
    if (md.iskVersion < SRZ_V0_7_0) {
    	f.read((char *) &(md.isTrial), sizeof(int));
    }

	// platform
	f.read((char *) &(md.compilePlat), sizeof(int));
	if (!f.good()) {
		cerr << "ERROR bad file while reading platf" << endl;
		return md;
	}

	// ok, I have some valid metadata
	md.isValidMetadata = 1;

	return md;
}
开发者ID:jannson,项目名称:iskdaemon,代码行数:35,代码来源:imgdb.cpp

示例10: loadFromStream

bool ContainerRecord::loadFromStream(std::ifstream& inStream)
{
  if (!inStream.good())
  {
    DuskLog() << "ContainerRecord::loadFromStream: ERROR: stream contains errors!\n";
    return false;
  }
  uint32_t len = 0;
  inStream.read((char*) &len, sizeof(uint32_t));
  if (len != cHeaderCont)
  {
    DuskLog() << "ContainerRecord::loadFromStream: ERROR: stream contains unexpected header!\n";
    return false;
  }
  char ID_Buffer[256];
  memset(ID_Buffer, 0, 256);
  //read ID
  len = 0;
  inStream.read((char*) &len, sizeof(uint32_t));
  if (len>255)
  {
    DuskLog() << "ContainerRecord::loadFromStream: ERROR: ID is "
              << "longer than 255 characters!\n";
    return false;
  }
  inStream.read(ID_Buffer, len);
  if (!inStream.good())
  {
    DuskLog() << "ContainerRecord::loadFromStream: ERROR while "
              << "reading ID from stream!\n";
    return false;
  }
  //read Mesh
  char Mesh_Buffer[256];
  memset(Mesh_Buffer, 0, 256);
  len = 0;
  inStream.read((char*) &len, sizeof(uint32_t));
  if (len>255)
  {
    DuskLog() << "ContainerRecord::loadFromStream: ERROR: mesh path "
              << "is longer than 255 characters!\n";
    return false;
  }
  inStream.read(Mesh_Buffer, len);
  if (!inStream.good())
  {
    DuskLog() << "ContainerRecord::loadFromStream: ERROR while "
              << "reading mesh path from stream!\n";
    return false;
  }
  Inventory temp;
  if (!temp.loadFromStream(inStream))
  {
    DuskLog() << "ContainerRecord::loadFromStream: ERROR while "
              << "reading inventory contens from stream!\n";
    return false;
  }
  //all right so far
  return inStream.good();
}
开发者ID:Thoronador,项目名称:Dusk,代码行数:60,代码来源:ContainerRecord.cpp

示例11:

//-------------------------INTERFACE------------------------
BOOL IFileManager::ImportFile_3DS(
	NFilePath pFilePath,
	std::vector<NVECTOR3>& outVertexBuffer, 
	std::vector<NVECTOR2>& outTexCoordList, 
	std::vector<UINT>& outIndexBuffer, 
	std::vector<N_MeshSubsetInfo>& outSubsetList, 
	std::vector<N_Material>& outMaterialList,
	std::unordered_map<std::string, NFilePath>& out_TexName2FilePathPairList)
{
	static_meshObjList.clear();
	static_materialList.clear();
	static_TexName2FilePathPairList.clear();

	fileIn.open(pFilePath, std::ios::binary);

	if (!fileIn.good())
	{
		DEBUG_MSG1("Noise File Manager : Import .3ds file failed!!");
		return FALSE;
	}

	fileIn.seekg(0, std::ios::end);
	static_currentChunkFileEndPos = 0;
	static_fileSize = fileIn.tellg();
	fileIn.seekg(0);

	//maybe linearly deal with chunks is also OK....
	//stack will be used when necessary because recursive solution
	//can sometimes be rewritten in non-recursive form using stack.
	while (!fileIn.eof() && fileIn.good())
	{
		ReadChunk();
	}
	fileIn.close();

	//Finish Parsing,check if Vertices/Indices had been loaded
	auto& vertexList = static_meshObjList.back().verticesList;
	if (vertexList.size() == 0 || vertexList.size() == 0)
	{
		DEBUG_MSG1("Noise File Manager :Data Damaged!!!No Vertices or Indices loaded!");
		return FALSE;
	}


	//std::move transform lval into rval to avoid copying happens
	N_Load3ds_MeshObject finalMeshObj;
	IntegratePartialMeshIntoOnePiece(finalMeshObj);
	outIndexBuffer = std::move(finalMeshObj.indicesList);
	outVertexBuffer = std::move(finalMeshObj.verticesList);
	outTexCoordList = std::move(finalMeshObj.texcoordList);
	outSubsetList = std::move(finalMeshObj.subsetList);
	outMaterialList = std::move(static_materialList);
	out_TexName2FilePathPairList = std::move(static_TexName2FilePathPairList);

	//used to generate unique name
	++static_MeshIndex;

	return TRUE;
}
开发者ID:CHINA-JIGE,项目名称:Noise3D-DirectX11,代码行数:60,代码来源:NBASE_FileMgr_3DS.cpp

示例12: map_file

/**
 * @brief read correlator meta-data and map to file positions
 * @description Nissa text correlator files contain meta-data in the form
 *              of comment lines. One line gives information about the
 *              contracted propagators in the form
 *
 *                S0_th0_m0_r0_ll ^ \dag S0_th0_m0_r0_ll
 *
 *              where we are (currently) interested in the indices
 *              on the m and r tokens. Another comment line specifies
 *              the spin content of the correlator in the form
 *              "P5P5" or "V1A0", for example. This function
 *              reads through the whole file and extracts the two
 *              m and two r indices as well as the spin combination.
 *              It constructs a key based on this information and stores
 *              the file position of the character after the newline behind
 *              the spin combination tag. Thus it stores the position of the
 *              beginning of the correlator corresponding to the constructed key.
 *
 * @param ifs file to be parsed
 * @param filemap output, map of file positions for the various correlators in the file
 */
inline void map_file(std::ifstream &ifs, std::map<std::string, std::iostream::pos_type> & filemap){
  if( !ifs.good() ){
    stop("map_file: input file stream not in a good state!");
  }

  std::string linebuf;
  std::string::size_type comment_pos;

  // currently the key for a two-point function consists of four unsigned integers (two mass and two r indices)
  // and the name of the spin combination stored in the correlator
  // a generalisation of the reader will have to modify this as well as the key construction
  // for now we store the numeric key components in this array
  unsigned int key_components[4];

  while( ifs.good() ){
    std::getline(ifs, linebuf);
    // we search for commented lines
    comment_pos = linebuf.find("#");
    if( comment_pos != std::string::npos ){
      // in these commented lines, we extract either
      // the current set of mass / r parameter combinations
      // or the current spin combination
      // the line looks like so:
      // " # Contraction of S0_th0_m0_r0_ll ^ \dag and S0_th0_m0_r0_ll"
      std::string::size_type contr_pos = linebuf.find("Contraction");
      if( contr_pos != std::string::npos ){
        std::vector<char> lbcopy( linebuf.size() + 1 );
        lbcopy[ linebuf.size() ] = '\0';
        memcpy( lbcopy.data(), linebuf.c_str(), linebuf.size() );
        unsigned int key_components_counter = 0;
        char * token = strtok(lbcopy.data(), "_");
        while( key_components_counter != 4 | token != NULL ){
          if( token[0] == 'm' || token[0] == 'r'){
            key_components[key_components_counter] = atoi(token+1);
            key_components_counter++;
          }
          token = strtok(NULL, "_");
        }
        if(key_components_counter != 4 && token == NULL){
          char message[200];
          snprintf(message, 200, "map_file: unable to construct key components in parsing of '%s'", linebuf.c_str());
          stop(message);
        }
      } else {
        // the line looks like so:
        // " # P5S0"
        std::string::size_type last_space_pos = linebuf.find_last_of(" ");
        std::string spin_comb = linebuf.substr(last_space_pos+1);
        // now we can build the key
        std::string key = make_key_2pt(key_components[0], key_components[2], key_components[1], key_components[3], spin_comb);
        // and store the position after the current newline as the starting point
        // of the present correlator
        filemap[ key ] = ifs.tellg();
      }
    }
  }
}
开发者ID:etmc,项目名称:hadron,代码行数:79,代码来源:read_nissa_textcf_kernel.cpp

示例13: loadFromStream

bool ObjectRecord::loadFromStream(std::ifstream& inStream)
{
  unsigned int len;
  uint32_t Header = 0;
  char ID_Buffer[256], Mesh_Buffer[256];

  //read header "ObjS" (Object, Static)
  inStream.read((char*) &Header, sizeof(uint32_t));
  if (Header!=cHeaderObjS)
  {
    DuskLog() << "ObjectRecord::loadFromStream: ERROR: Stream contains invalid "
              << "record header.\n";
    return false;
  }//if
  //read length of ID
  inStream.read((char*) &len, sizeof(unsigned int));
  if (len>255)
  {
    DuskLog() << "ObjectRecord::loadFromStream: ERROR: ID cannot be longer than "
              << "255 characters.\n";
    return false;
  }
  //read ID
  memset(ID_Buffer, 0, 256);
  inStream.read(ID_Buffer, len);
  ID_Buffer[len] = '\0'; //add terminating null character
  if (!inStream.good())
  {
    DuskLog() << "ObjectRecord::loadFromStream: ERROR while reading data.\n";
    return false;
  }
  //read length of mesh name
  inStream.read((char*) &len, sizeof(unsigned int));
  if (len>255)
  {
    DuskLog() << "ObjectRecord::loadFromStream: ERROR: Name of Mesh cannot be "
              << "longer than 255 characters.\n";
    return false;
  }
  //read mesh
  memset(Mesh_Buffer, 0, 256);
  inStream.read(Mesh_Buffer, len);
  Mesh_Buffer[len] = '\0'; //add terminating null character
  //read collision flag
  bool collision_flag = true;
  inStream.read((char*) &collision_flag, sizeof(bool));
  if (!inStream.good())
  {
    DuskLog() << "ObjectRecord::loadFromStream: ERROR while reading data.\n";
    return false;
  }
  //now set the data
  ID = std::string(ID_Buffer);
  Mesh = std::string(Mesh_Buffer);
  collide = collision_flag;
  return true;
}
开发者ID:Thoronador,项目名称:Dusk,代码行数:57,代码来源:ObjectRecord.cpp

示例14: sigintHandler

void sigintHandler(int a)
{
    while(footer_kml.good())
    {
        char c = footer_kml.get();       // get character from file
            if (footer_kml.good())
             kml_file << c;
    }
    kml_file << std::endl;

    ros::requestShutdown();
}
开发者ID:idaohang,项目名称:ros_gps_useful_tools,代码行数:12,代码来源:kml_extractor_node.cpp

示例15: get_next_line

void get_next_line(std::ifstream& file, std::string& line)
{
	bool comment=false;
	do {
		getline(file,line);
		if (file.good() && line.size()>0)
			if (line[0]=='#')
				comment=true;
			else
				comment=false;
	} while (file.good() && comment);
}
开发者ID:jakobmatthes,项目名称:fragrep,代码行数:12,代码来源:fragrep.cpp


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