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


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

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


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

示例1: readVectorData

    inline void readVectorData(std::istream& is, std::vector<T>& data)
    {
	data.clear();
	while (is) {
	    T candidate;
	    is >> candidate;
	    if (is.rdstate() & std::ios::failbit) {
		is.clear(is.rdstate() & ~std::ios::failbit);
                is >> ignoreWhitespace;
		char dummy;
		is >> dummy;
		if (dummy == '/') {
                    is >> ignoreLine;
		    break;
		} else if (dummy == '-') {  // "comment test"
开发者ID:00liujj,项目名称:opm-core,代码行数:15,代码来源:EclipseGridParserHelpers.hpp

示例2: gene

int
GA3DBinaryStringGenome::read(std::istream & is)
{
  static char c;
  unsigned int i=0, j=0, k=0;
  do{
    is >> c;
    if(isdigit(c)){
      gene(i++, j, k, ((c == '0') ? 0 : 1));
      if(i >= nx){
	i=0;
	j++;
      }
      if(j >= ny){
	j=0;
	k++;
      }
    }
  } while(!is.fail() && !is.eof() && k < nz);

  _evaluated = gaFalse;

  if(is.eof() && 
     ((k < nz) ||		// didn't get some lines
      (j < ny && j != 0) ||	// didn't get some lines
      (i < nx && i != 0))){	// didn't get some lines
    GAErr(GA_LOC, className(), "read", gaErrUnexpectedEOF);
    is.clear(std::ios::badbit | is.rdstate());
    return 1;
  }

  return 0;
}
开发者ID:backo880607,项目名称:YuKonSolution,代码行数:33,代码来源:GA3DBinS.cpp

示例3: set

    void set(std::istream& in, std::ostream& out, std::ostream& err) {
      if (not activated) {
	using namespace std;
	in_buf = cin.rdbuf(); out_buf = cout.rdbuf(); err_buf = cerr.rdbuf();
	in_state = cin.rdstate(); out_state = cin.rdstate(); err_state = cerr.rdstate();
	cin.rdbuf(in.rdbuf()); cout.rdbuf(out.rdbuf()); cerr.rdbuf(err.rdbuf());
	cin.exceptions(ios_base::goodbit); cout.exceptions(ios_base::goodbit); cerr.exceptions(ios_base::goodbit);
	cin.clear(in.rdstate()); cout.clear(out.rdstate()); cerr.clear(err.rdstate());
      }
    }
开发者ID:PJames,项目名称:oklibrary,代码行数:10,代码来源:StreamHandling.hpp

示例4: checkFileState

bool checkFileState(std::istream& unbuiltFile, std::istream& builtFile) {
  // check for the stream state flags
  if (unbuiltFile.eof()) {
    if (! builtFile.eof()) {
      throw runtime_error("unbuilt file contains more data than unbuilt");
    }
  }
  if (builtFile.eof()) {
    if (! unbuiltFile.eof()) {
      throw runtime_error("built file contains more data than unbuilt");
    }
  }
  if (unbuiltFile.rdstate()!=0 && !unbuiltFile.eof()) {
    throw runtime_error("Unbuilt file has error state");
  }

  if (builtFile.rdstate()!=0 && ! builtFile.eof()) {
    throw runtime_error("Built file has error state");
  }

  return (builtFile.eof() || unbuiltFile.eof());
}
开发者ID:jrtomps,项目名称:compare_evts,代码行数:22,代码来源:main.cpp

示例5:

std::vector<Point> Calibrator::loadPoints(std::istream &in) {
	std::vector<Point> result;

	for(;;) {
		double x, y;
		in >> x >> y;
		if (in.rdstate()) {
			// break if any error
			break;
		}
		result.push_back(Point(x, y));
	}

	return result;
}
开发者ID:MariadeAnton,项目名称:OpenGazer,代码行数:15,代码来源:Calibrator.cpp

示例6: check_failedload

/*!
 * \brief Check for a failure during the last stream input.
 *
 * If the last stream input did not succeed, throws an exception with
 * details on the stream position where this occurred.
 */
void check_failedload(std::istream &is)
   {
   if (is.fail())
      {
      std::ios::iostate state = is.rdstate();
      is.clear();
      std::ostringstream sout;
      sout << "Failure loading object at position " << is.tellg()
            << ", next line:" << std::endl;
      std::string s;
      getline(is, s);
      sout << s;
      is.clear(state);
      throw load_error(sout.str());
      }
   }
开发者ID:jbresearch,项目名称:simcommsys,代码行数:22,代码来源:config.cpp

示例7: runtime_error

xml_lmi::dom_parser::dom_parser(std::istream const& is)
{
    try
        {
        error_context_ = "Unable to parse xml stream: ";
        if(0 != is.rdstate())
            {
            throw std::runtime_error("Stream state is not 'good'.");
            }
        std::string s;
        istream_to_string(is, s);
        parser_.reset(new DomParser(s.c_str(), 1 + s.size()));
        }
    catch(std::exception const& e)
        {
        fatal_error() << error_context_ << e.what() << LMI_FLUSH;
        }
}
开发者ID:vadz,项目名称:lmi.new,代码行数:18,代码来源:xml_lmi.cpp

示例8: read_known

bool VersionedFileHeader::read_known( VFH_Type i_type, std::istream &io_istream )
{
	// save stream state and position
	streampos pos   = io_istream.tellg();
	ios_base::iostate state = io_istream.rdstate();

	if ( !read_raw( io_istream ) ||
	     m_magicNumber!=(isMSBF()?g_versioned_headers_list[i_type].magic_number_MSBF:g_versioned_headers_list[i_type].magic_number_LSBF) )
	{
		// reading failed, rewind to starting point and reset error flags
		io_istream.seekg( pos );
		io_istream.setstate( state );
		m_magicNumber = m_version = 0;
		m_isMSBF = MSBF_PROCESSOR();
		return false;
	}
	return true;
}
开发者ID:,项目名称:,代码行数:18,代码来源:

示例9: read_unknown

bool VersionedFileHeader::read_unknown( std::istream &io_istream, VFH_Type &o_id )
{
	// save stream state and position
	streampos pos   = io_istream.tellg();
	ios_base::iostate state = io_istream.rdstate();

	bool isMSBF_; // from magic number
	if ( !read_raw( io_istream ) ||
	     !typeFromMagicNumber(m_magicNumber, o_id, isMSBF_) ||
	     isMSBF_!=isMSBF() )
	{
		// reading failed, rewind to starting point and reset error flags
		io_istream.seekg( pos );
		io_istream.setstate( state );
		return false;
	}
	return true;
}
开发者ID:,项目名称:,代码行数:18,代码来源:

示例10: read

void Date::read(std::istream& in) {
    int in_day { }, in_month { }, in_year { };
    char sep1 { }, sep2 { };
    in >> in_day >> sep1 >> in_month >> sep2 >> in_year;
    if (isValidDate(1,1,1)) //should be  (isValidYear(in_day))
        std::swap(in_day, in_year);
    if (in_year >= 0 && in_year < 100)
        in_year += 2000;
    if (!in.fail() && sep1 == sep2
        && (sep1 == '.' || sep1 == '/' || sep1 == '-')
        && isValidDate(in_year, in_month, in_day)) {
        year = in_year;
        month = in_month;
        day = in_day;
    } else {
        in.setstate(std::ios::failbit | in.rdstate());
    }
}
开发者ID:aerobless,项目名称:HSR_Prog3,代码行数:18,代码来源:Date.cpp

示例11: gene

int GA1DArrayAlleleGenome<char>::read(std::istream & is)
{
    unsigned int i = 0;
    char c;
    do
    {
        is.get(c);
        if(!is.fail())
        {
            gene(i++, c);
        }
    }
    while(!is.fail() && !is.eof() && i < nx);

    if(is.eof() && i < nx)
    {
        GAErr(GA_LOC, className(), "read", gaErrUnexpectedEOF);
        is.clear(std::ios::badbit | is.rdstate());
        return 1;
    }
    return 0;
}
开发者ID:distanceModling,项目名称:GAlib,代码行数:22,代码来源:GAStringGenome.C

示例12: gene

/// The read specialization takes in each number and stuffs it into the array.
template <> int
GA1DArrayAlleleGenome<float>::read(std::istream & is)
{
    unsigned int i = 0;
    float val;
    do
    {
        is >> val;
        if(!is.fail())
        {
            gene(i++, val);
        }
    }
    while(!is.fail() && !is.eof() && i < nx);

    if(is.eof() && i < nx)
    {
        GAErr(GA_LOC, className(), "read", gaErrUnexpectedEOF);
        is.clear(std::ios::badbit | is.rdstate());
        return 1;
    }
    return 0;
}
开发者ID:distanceModling,项目名称:GAlib,代码行数:24,代码来源:GARealGenome.C

示例13: in

    std::ostream& operator<<(std::ostream& out, const ostrstream& x) {
        out << static_cast<strstreambuf*>(x.rdbuf())->str();
        return out;
    }

    class istrstream : public std::istream {
        strstreambuf sb;
    public:
        istrstream(char* buf) : sb(buf) { }

        template<class T>
        istrstream& operator>>(T& x) {
            std::istream in(&sb);
            in.copyfmt(*this);
            in >> x;
            setstate(in.rdstate());
            return *this;
        }
    };
}

int main() {
    using namespace std;
    using namespace ch21;

    char buf[1024];
    ostrstream out(buf, 1024);
    out << "foo bar " << 12345;
    cout << out << endl;

    istrstream in(buf);
开发者ID:Nobody-7,项目名称:tcpppl_answers,代码行数:31,代码来源:ex26.cpp

示例14: vtkReadBinaryData

int32_t vtkReadBinaryData(std::istream& in, T* data, int32_t numTuples, int32_t numComp)
{
  if (numTuples == 0 || numComp == 0)
  {
    // nothing to read here.
    return 1;
  }

  size_t numBytesToRead = static_cast<size_t>(numTuples) * static_cast<size_t>(numComp) * sizeof(T);
  size_t numRead = 0;
  // Cast our pointer to a pointer that std::istream will take
  char* chunkptr = reinterpret_cast<char*>(data);

  numRead = 0;
  // Now start reading the data in chunks if needed.
  size_t chunkSize = DEFAULT_BLOCKSIZE;
  // Sanity check the chunk size to make sure it is not any larger than the chunk of data we are about to read
  if (numBytesToRead < DEFAULT_BLOCKSIZE)
  {
    chunkSize = numBytesToRead;
  }

  size_t master_counter = 0;
  size_t bytes_read = 0;

  // Now chunk through the file reading up chunks of data that can actually be
  // read in a single read. DEFAULT_BLOCKSIZE will control this.
  while(1)
  {
    in.read(chunkptr, chunkSize);
    bytes_read = in.gcount();

    chunkptr = chunkptr + bytes_read;
    master_counter += bytes_read;

    if (numBytesToRead - master_counter < chunkSize)
    {
      chunkSize = numBytesToRead - master_counter;
    }
    if (master_counter >= numBytesToRead)
    {
      break;
    }
    if (in.good())
    {
      //std::cout << "all data read successfully." << in.gcount() << std::endl;
    }

    if ((in.rdstate() & std::ifstream::failbit) != 0)
    {
      std::cout << "FAIL " << in.gcount() << " could be read. Needed " << chunkSize << " total bytes read = " << master_counter << std::endl;
      return -12020;
    }
    if ((in.rdstate() & std::ifstream::eofbit) != 0)
    {
      std::cout << "EOF " << in.gcount() << " could be read. Needed " << chunkSize << " total bytes read = " << master_counter << std::endl;
      return -12021;
    }
    if ((in.rdstate() & std::ifstream::badbit) != 0)
    {
      std::cout << "BAD " << in.gcount() << " could be read. Needed " << chunkSize << " total bytes read = " << master_counter << std::endl;
      return -12021;
    }
  }
  return 0;
}
开发者ID:BlueQuartzSoftware,项目名称:DREAM3D,代码行数:66,代码来源:VtkStructuredPointsReader.cpp


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