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


C++ istream::bad方法代码示例

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


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

示例1: createJobFile

static bool createJobFile(istream &src, const string &destFile, const Args &args)
{
    Log::debug("Create job file %s", destFile.c_str());

    ofstream dest(destFile, ios::binary | ios::trunc);
    dest << "\033CUPS_BOOMAGA\n";
    dest << "JOB="     << escapeString(args.jobID)   << "\n";
    dest << "USER="    << escapeString(args.user)    << "\n";
    dest << "TITLE="   << escapeString(args.title)   << "\n";
    dest << "COUNT="   << args.count                 << "\n";
    dest << "OPTIONS=" << escapeString(args.options) << "\n";
    dest << "CUPS_BOOMAGA_DATA\n";
    dest << src.rdbuf();
    dest.close();

    if (src.bad() || !dest.good())
    {
        Log::debug("Delete file %s", destFile.c_str());
        unlink(destFile.c_str());
        Log::error("Can't create job file: %s", strerror(errno));
        return false;
    }

    if (chown(destFile.c_str(), args.pwd->pw_uid, -1) != 0)
    {
        Log::error("Can't change owner on directory %s: %s", destFile.c_str(), std::strerror(errno));
        return false;
    }

    return true;
}
开发者ID:Boomaga,项目名称:boomaga,代码行数:31,代码来源:main.cpp

示例2: read_func_labeled

//read coefficients from a stream. This assumes pairs of bitstring and values, e.g.
//010100 1.232
//101011 65.432
int hypercube_lowd::read_func_labeled(istream &in)
{
	int i=0, count;
	char gt[dim+2];
	if (in.bad())
	{
		cerr <<"hypercube_lowd::read_func_labeled: bad stream\n";
		return HC_BADARG;
	}
	count=0;
	while(in.good() && count<(1<<dim))
	{
		i=0;
		in >>gt;
		for (int k=0; k<dim; k++)
			if (gt[k]=='1') i+=1<<k;
		in >>func[i];
		count++;
		in.ignore(100, '\n');
	}
	if (count<(1<<dim))
	{
		cerr <<"hypercube_lowd::read_func: file end reached after "<<i<<" values!\n";
		return HC_BADARG;
	}
	return 0;
}
开发者ID:iosonofabio,项目名称:ffpopsim,代码行数:30,代码来源:hypercube_lowd.cpp

示例3: seekToFirstTree

void seekToFirstTree(istream &inputFile)
{
    if (DEBUG_OUTPUT >= 3){
        cout << "seekToFirstTree called." << endl;
    }
    string fileInputUpper;
    getline(inputFile,fileInputUpper);
    if (inputFile.bad()) {
        cout << "Can not read file given to seekToFirstTree." << endl;
        exit (0);
    }
    transform(fileInputUpper.begin(), fileInputUpper.end(),fileInputUpper.begin(), ::toupper);
    while (!( fileInputUpper.find("TREE") != string::npos && fileInputUpper.find("=") != string::npos))
    {
        if (DEBUG_OUTPUT >= 3){
            cout << fileInputUpper.substr(0,40) << endl;
        }
        getline(inputFile,fileInputUpper);
        if (inputFile.bad()) {
            cout << "Can not read file given to seekToFirstTree." << endl;
            exit (0);
        }
        transform(fileInputUpper.begin(), fileInputUpper.end(),fileInputUpper.begin(), ::toupper);
    }
    if (DEBUG_OUTPUT >= 3){
        cout << fileInputUpper.substr(0,40) << endl;
        cout << "inputFile.tellg(): "   << inputFile.tellg() << endl;
        cout << "inputFile.bad(): "     << inputFile.bad() << endl;
        cout << "inputFile.good(): "    << inputFile.good() << endl;
        cout << "inputFile.eof(): "     << inputFile.eof() << endl;
        cout << "inputFile.rdstate(): " << inputFile.rdstate() << endl;
    }
    // Something is happening to Peter's computer here!
    int curPosition = inputFile.tellg();
    // This might be causing problems to seek negative int from cur position
    // inputFile.seekg(-(fileInputUpper.size()+1),ios_base::cur);
    inputFile.seekg( curPosition - ((fileInputUpper.size()+1)), ios_base::beg);
    if (DEBUG_OUTPUT >= 3){
        cout << "inputFile.tellg(): " << inputFile.tellg() << endl;
        cout << "inputFile.bad(): " << inputFile.bad() << endl;
        cout << "inputFile.good(): " << inputFile.good() << endl;
        cout << "inputFile.eof(): " << inputFile.eof() << endl;
        cout << "inputFile.rdstate(): " << inputFile.rdstate() << endl;
        cout << "seekToFirstTree done." << endl;
    }
}
开发者ID:dchaws,项目名称:GeneOut,代码行数:46,代码来源:treefuncs.cpp

示例4: GetALineFromStream

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
void GetALineFromStream(string &LineString, istream &Datastream)
{
	char Buffer;
	

	if(!Datastream.eof())
	{
		Datastream.get(Buffer);

	}
	else
	{
		return;
	}
	
	if(Datastream.bad())
	{
		throw exception("GetALineFromStream Error when iostream Get get(Buffer); File:__FILE__;Line:__LINE__");
	}
	
	while(Buffer!='\n')
	{
		
		
     	
	    if(!Datastream.eof())
		{
			LineString += Buffer;
			Datastream.get(Buffer);
			
		
		}
		else
		{
			break;
		}
		
		if(Datastream.bad())
		{
			throw exception("GetALineFromStream Error when iostream Get get(Buffer); File:__FILE__;Line:__LINE__");
		}
		 
	}

}
开发者ID:XeanoRRR,项目名称:mmo-resourse,代码行数:48,代码来源:ItermProcess.cpp

示例5: while

void
readFasta(istream& istr, SQDict& dict, bool parseSeqOffset)
{
  string name;
  vector<char> buffer;

  while (true) {
    string s;
    getline(istr, s);
    if (istr.bad()) {
      cerr << "error reading SAM file" << endl;
      exit(1);
    }
    if (istr.eof() or s[0] == '>') {
      if (name.length() > 0) {
	// add previous sequence
	long long int seqOffset = 0;
	if (parseSeqOffset) {
	  int j = name.find(':');
	  if (j < (int)name.length()) {
	    seqOffset = atoll(&name.c_str()[j + 1]) - 1;
	    name = name.substr(0, j);
	  }
	}
	Contig& c = dict[name];
	if (c.name.length() == 0) {
	  c.name = name;
	  c.len = buffer.size();
	  c.idx = dict.size() - 1;
	  c.seq[0] = DNASequence(buffer.begin(), buffer.end());
	  c.seqOffset[0] = seqOffset;
	  cerr << "added contig [" << c.name << "] of length [" << c.len << "]"
	       << " with start offset [" << c.seqOffset[0] << "]" << endl;
	}
      }
      if (istr.eof())
	break;
      int stop = s.find(" ")-1;
      if (stop > 0) {
      	name = s.substr(1,stop);
      } else {
      	name = s.substr(1);
      }
      buffer.clear();
    } else {
      buffer.insert(buffer.end(), s.begin(), s.end());
    }
  }
}
开发者ID:compbio-UofT,项目名称:alu-detect,代码行数:49,代码来源:Fasta.cpp

示例6: printStreamState

void printStreamState(const istream& istr)
{
	if (istr.good()) {
		cout << "stream state is good" << endl;
	}
	if (istr.bad()) {
		cout << "stream state is bad" << endl;
	}
	if (istr.fail()) {
		cout << "stream state is fail" << endl;
	}
	if (istr.eof()) {
		cout << "stream state is eof" << endl;
	}
}
开发者ID:JianboTang,项目名称:Professional_CPP,代码行数:15,代码来源:ArticleCitations.cpp

示例7: set

//--------------------------------------------------
bool ofBuffer::set(istream & stream){
	if(stream.bad()){
		clear();
		return false;
	}else{
		buffer.clear();
	}

	vector<char> aux_buffer(ioSize);
	while(stream.good()){
		stream.read(&aux_buffer[0], ioSize);
		buffer.insert(buffer.end(),aux_buffer.begin(),aux_buffer.begin()+stream.gcount());
	}
	buffer.push_back(0);
	return true;
}
开发者ID:Daandelange,项目名称:openFrameworks,代码行数:17,代码来源:ofFileUtils.cpp

示例8: read_one_line

inline bool read_one_line(istream& strm, std::string& /*output*/ line)
{
	getline(strm, line);

	if (strm.eof())
		return false;

	if (strm.bad() || strm.fail()) {
		err(1,"Error: failed to read from file '%s'", current_file_name.c_str());
	}

	++current_line;
	++lines_in_current_file;

	return true;
}
开发者ID:agordon,项目名称:fastx_read_count,代码行数:16,代码来源:main.cpp

示例9: read_resistance_coefficients

int hivpopulation::read_resistance_coefficients(istream &model){
	if (HIVPOP_VERBOSE){
		cerr<<"hivpopulation::read_resistance_coefficients(): read coefficients ";
	}
	if (model.bad()){
		cerr<<"hivpopulation::read_resistance_coefficients(): BAD MODEL STREAM!"<<endl;
		return HIVPOP_BADARG;
	}
	double val, wt_resistance=0;
	vector <int> loci;
	vector<string> strs;
	string line;

	// reset the hypercube
	trait[1].reset();
	
	// read the stream
	while(!model.eof()){
		strs.clear();
		loci.clear();
		getline(model, line);
		boost::split(strs, line, boost::is_any_of("\t "));
		//cout <<"a "<<line<<"  "<<strs.size();
		if (strs.size()>1){
			for (unsigned int entry=0; entry<strs.size()-1; entry++){
				loci.push_back(atoi(strs[entry].c_str()));
				//cout<<loci.back()<<" "<<strs[entry].c_str()<<"  ";
			}
			val=atof(strs.back().c_str());
			add_trait_coefficient(val, loci,1);
			wt_resistance+=val*pow(-1.0,(double)loci.size());
			//cout <<loci.size()<<"  "<<wt_resistance<<endl;
		}
		//cout<<loci[0]<<" "<<val<<"  "<<loci.size()<<endl;
	}
	trait[1].hypercube_mean=-wt_resistance;

	// update the replication and fitness of all clones
	update_traits();
	update_fitness();

	if (HIVPOP_VERBOSE){
		cerr<<"...done"<<endl;
	}
	return 0;
}
开发者ID:iosonofabio,项目名称:ffpopsim,代码行数:46,代码来源:hivpopulation.cpp

示例10: ofs

void zipios::ZipOutputStreamTest::entryToFile(const string &ent_name, istream &is, 
					      const string &outfile,
                                              bool cerr_report) {
  ofstream ofs( outfile.c_str(), ios::out | ios::binary ) ;
  
  
  ofs << is.rdbuf() ;
  if ( cerr_report ) {
    cerr << "writing " << ent_name << " to " << outfile << endl ;
    cerr << "Stream state: "  ;
    cerr << "good() = " << is.good() << ",\t" ;
    cerr << "fail() = " << is.fail() << ",\t" ;
    cerr << "bad()  = " << is.bad()  << ",\t" ;
    cerr << "eof()  = " << is.eof()  << endl << endl;
  }
  ofs.close() ;
}
开发者ID:ming81,项目名称:zipios,代码行数:17,代码来源:zipoutputstreamtest.cpp

示例11: Load

bool MilestonePath::Load(istream& in,CSpace* space)
{
  Assert(space != NULL);
  vector<Config> configs;
  int n;
  in>>n;
  if(in.bad()) return false;
  Assert(n > 0);
  configs.reserve(n);
  Config temp;
  for(int i=0;i<n;i++) {
    in>>temp;
    configs.push_back(temp);
  }
  CreateEdgesFromMilestones(space,configs);
  return true;
}
开发者ID:jmainpri,项目名称:KrisLibrary,代码行数:17,代码来源:Path.cpp

示例12: readScheme

static vector<pair<string, set<set<string> > > > readScheme(istream& in){
  vector<string> lines;
  string s;
  while(getline(in, s)){
    s.erase(remove_if(s.begin(), s.end(), ::isspace), s.end());
    if(!s.empty())
      lines.push_back(s);
    if(in.fail() || in.eof())
      break;
  }
  if(in.bad())
    report_fatal_error("error encountered reading schema input");
  
  vector<pair<string, set<set<string> > > > result;
  
  for(vector<string>::iterator i = lines.begin(), e = lines.end(); i != e; ++i){
    vector<string> entries = split(*i, ';');
    if(entries.size() < 2)
      report_fatal_error("invalid formatting for line '" + *i + "' in instrumentation schema");
    
    string fnPattern = entries[0];
    set<set<string> > schemes;
    for(vector<string>::iterator j = ++entries.begin(), je = entries.end(); j != je; ++j){
      string scheme = *j;
      transform(scheme.begin(), scheme.end(), scheme.begin(), ::toupper);
      if(scheme[0] != '{' || scheme[scheme.length()-1] != '}')
        report_fatal_error("invalid formatting for entry '" + scheme + "' in instrumentation schema", false);
      scheme.erase(0, 1);
      scheme.erase(scheme.length()-1, 1);
      
      const vector<string> methods = split(scheme, ',');
      set<string> methodsSet;
      for(vector<string>::const_iterator k = methods.begin(), ke = methods.end(); k != ke; ++k){
        if(!k->empty())
          methodsSet.insert(*k);
      }
      
      schemes.insert(methodsSet);
    }
    
    result.push_back(make_pair(fnPattern, schemes));
  }
  
  return(result);
}
开发者ID:chubbymaggie,项目名称:csi-cc,代码行数:45,代码来源:PrepareCSI.cpp

示例13: Load

bool LinearPathResource::Load(istream& in)
{
  times.clear();
  milestones.clear();
  Real t;
  Vector x;
  while(in) {
    in >> t >> x;
    if(in) {
      times.push_back(t);
      milestones.push_back(x);
    }
  }
  if(in.bad()) {
    return false;
  }
  return true;
}
开发者ID:RGrant92,项目名称:Klampt,代码行数:18,代码来源:Resources.cpp

示例14: fillVector

void fillVector(vector<int> &v, istream &ist, char terminator)
{
	int x;
	while(ist >> x)
		v.push_back(x);
	if(ist.bad())
		error("Some unusual error occurred, stream is in bad state.");
	if(ist.eof())
		return;
	if(ist.fail()) {
		ist.clear();	// clear stream state
		char c;
		ist >> c;
		if(c == terminator) {
			cout << "found terminator\n";
			return;
		}
		ist.unget();
		ist.clear(ios_base::failbit);	// set the state to fail
	}
开发者ID:kaustubhb,项目名称:PPPCpp,代码行数:20,代码来源:fillvector.cpp

示例15: readCentralDirectory

bool ZipFile::readCentralDirectory ( istream &_zipfile ) {
  // Find and read eocd. 
  if ( ! readEndOfCentralDirectory( _zipfile ) )
    throw FCollException( "Unable to find zip structure: End-of-central-directory" ) ;

  // Position read pointer to start of first entry in central dir.
  _vs.vseekg( _zipfile,  _eocd.offset(), ios::beg ) ;

  int entry_num = 0 ;
  // Giving the default argument in the next line to keep Visual C++ quiet
  _entries.resize ( _eocd.totalCount(), 0 ) ;
  while ( ( entry_num < _eocd.totalCount() ) ) {
    ZipCDirEntry *ent = new ZipCDirEntry ; 
    _entries[ entry_num ] = ent ;
    _zipfile >>  *ent ;
    if ( ! _zipfile ) {
      if ( _zipfile.bad()  ) 
	throw IOException( "Error reading zip file while reading zip file central directory" ) ;
      else if ( _zipfile.fail() )
	throw FCollException( "Zip file consistency problem. Failure while reading zip file central directory" ) ;
      else if ( _zipfile.eof()  )
	throw IOException( "Premature end of file while reading zip file central directory" ) ;
    }
    ++entry_num ;
  }

  // Consistency check. eocd should start here
  
  int pos = _vs.vtellg( _zipfile ) ;
  _vs.vseekg( _zipfile, 0, ios::end ) ;
  int remaining = static_cast< int >( _vs.vtellg( _zipfile ) ) - pos ;
  if ( remaining != _eocd.eocdOffSetFromEnd() )
    throw FCollException( "Zip file consistency problem. Zip file data fields are inconsistent with zip file layout" ) ;

  // Consistency check 2, are local headers consistent with
  // cd headers
  if ( ! confirmLocalHeaders( _zipfile ) )
    throw FCollException( "Zip file consistency problem. Zip file data fields are inconsistent with zip file layout" ) ;
  
  return true ;
}
开发者ID:ming81,项目名称:zipios,代码行数:41,代码来源:zipfile.cpp


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