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


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

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


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

示例1: recvfile

long long TCPTransport::recvfile(std::fstream& ofs, long long offset, long long size)
{
    if (!m_bConnected)
        return -1;

    if (ofs.bad() || ofs.fail())
        return -1;

    ofs.seekp(offset);

    int block = 1000000;
    char* buf = new char[block];
    long long recd = 0;
    while (recd < size)
    {
        int unit = int((size - recd) > block ? block : size - recd);
        recv(buf, unit);
        ofs.write(buf, unit);
        recd += unit;
    }

    delete [] buf;

    return recd;
}
开发者ID:superpig119,项目名称:MantouDB,代码行数:25,代码来源:tcptransport.cpp

示例2: sendfile

long long TCPTransport::sendfile(std::fstream& ifs, long long offset, long long size)
{
    if (!m_bConnected)
        return -1;

    if (ifs.bad() || ifs.fail())
        return -1;

    ifs.seekg(offset);

    int block = 1000000;
    char* buf = new char[block];
    long long sent = 0;
    while (sent < size)
    {
        int unit = int((size - sent) > block ? block : size - sent);
        ifs.read(buf, unit);
        send(buf, unit);
        sent += unit;
    }

    delete [] buf;

    return sent;
}
开发者ID:superpig119,项目名称:MantouDB,代码行数:25,代码来源:tcptransport.cpp

示例3: getImageCount

    static int getImageCount(std::fstream& file_list)
    {
        int sample = 0;
        std::string line;
        while (std::getline(file_list, line))
            ++sample;
        if (file_list.eof())
            file_list.clear();  //otherwise we can't do any further I/O
        else if (file_list.bad()) {
            throw  std::runtime_error("Error occured while reading files_list.txt");
        }

        return sample;
    }
开发者ID:Jinwei1,项目名称:AirSim,代码行数:14,代码来源:StereoImageGenerator.hpp

示例4: seek

	/**
	 * Sets the stream position indicator for the stream. The new position,
	 * measured in bytes, is obtained by adding offset bytes to the position
	 * specified by whence. If whence is set to SEEK_SET, SEEK_CUR, or
	 * SEEK_END, the offset is relative to the start of the file, the current
	 * position indicator, or end-of-file, respectively. A successful call
	 * to the seek() method clears the end-of-file indicator for the stream.
	 *
	 * @note The semantics of any implementation of this method are
	 * supposed to match those of ISO C fseek().
	 *
	 * @param offset	the relative offset in bytes
	 * @param whence	the seek reference: SEEK_SET, SEEK_CUR, or SEEK_END
	 * @return true on success, false in case of a failure
	 */
	virtual bool seek(int32 offset, int whence = SEEK_SET) {
		if (whence == SEEK_SET) {
			_stream->seekg(offset, std::ios::beg);
		} else if (whence == SEEK_CUR) {
			_stream->seekg(offset, std::ios::cur);
		} else {
			_stream->seekg(offset, std::ios::end);
		}
		
		if (_stream->fail())
			return false;
		if (_stream->bad())
			return false;
		return true;
	}
开发者ID:somaen,项目名称:Wintermute-git,代码行数:30,代码来源:myfilestream.cpp

示例5: leerLinea

void Agente::leerLinea(std::fstream& archivo, std::string& linea) {
	linea.clear();

	char buffer[T_BUFFER];

	bool seguirLeyendo = true;
	do {
		archivo.getline(buffer, T_BUFFER, '\n');
		linea.append(buffer, archivo.gcount());

		seguirLeyendo = (archivo.gcount() == T_BUFFER);

		if (archivo.bad())
			archivo.clear();

	} while (seguirLeyendo);
}
开发者ID:SebastianBogado,项目名称:fiuba-7542-tp-final,代码行数:17,代码来源:Agente.cpp

示例6: indices

//------------------------------------------------------------------------------
/// \brief Reads 3. Data: ITMP
/// \brief Reads 4. Data: WELLID Qdes {CapMult} {Cprime} {xyz}
//------------------------------------------------------------------------------
void ProcessorMNW2::impl::ReadStressPeriods (std::fstream& a_is,
                                             std::fstream& a_os)
{
  CStr str;
  std::string line;
  EReadAsciiFile e;
  e.UseExceptions();
  while (!a_is.bad())
  {
    std::getline(a_is, line);
    if (line.empty())
    {
      return;
    }

    int ITMP;
    a_os << line << "\n";
    e.SetLine(line.c_str());
    e.ReadData(ITMP);
    if (ITMP < 1)
      continue;

    std::getline(a_is, line);
    e.SetLine(line.c_str());
    e.ReadData(str);
    if ("GMS_HDF5_01" == str)
    {
      CStr fname, path;
      int sp;
      e.ReadData(fname);
      e.ReadData(path);
      path += "/07. Property";
      e.ReadData(sp);
      std::pair<int, int> myPair(0,1);
      VEC_INT_PAIR indices(3, myPair);
      indices[0].second = numMnw2Prop();
      indices[1].second = m_MNWMAX;
      indices[2].first = sp - 1;
      H5DataSetReader r(fname, path, indices);
      CAR_DBL2D vals;
      vals.SetSize(MNW2::NPROP, m_MNWMAX, 0);
      if (!r.GetData(&vals[0][0], MNW2::NPROP*m_MNWMAX))
      {
        ErrorStack::Get().PutError("Unable to read MNW2 hdf5 data.");
        throw ioError("");
      }

      for (int i = 0; i<m_MNWMAX; i++)
      {
        if (vals.at(MNW2::ACTIVE, i) != 0)
        { // this well is active
          // 4a. Data: WELLID Qdes {CapMult} {Cprime} {xyz}
          CStr ln;
          ln.Format("'%s' %s", m_wells.at(i).m_WELLID,
                               STR(vals.at(MNW2::QDES, i)));
          if (m_wells.at(i).m_PUMPCAP > 0)
          {
            ln += " ";
            ln += STR(vals.at(MNW2::CAPMULT, i));
          }
          // don't write Cprime

          // get AUX
          for (int j = 0; j<m_nAUX; j++)
          {
            ln += " ";
            ln += STR(vals.at(MNW2::AUX_0+j, i));
          }
          a_os << ln << "\n";

          if (m_wells.at(i).m_Qlimit < 0)
          {
            double QCUT = vals.at(MNW2::QCUT, i);
            ln.Format("%s %s", STR(vals.at(MNW2::HLIM, i)), STR(QCUT));
            if (QCUT != 0)
            {
              CStr ln2;
              ln2.Format(" %s %s", STR(vals.at(MNW2::QFRCMN, i)),
                                   STR(vals.at(MNW2::QFRCMX, i)));
              ln += ln2;
            }
            a_os << ln << "\n";
          }
        }
      }
    }
  }
} // ProcessorMNW2::impl::ReadStressPeriods
开发者ID:Aquaveo,项目名称:MFLib,代码行数:92,代码来源:ProcessorMNW2.cpp


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