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


C++ ofstream::fail方法代码示例

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


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

示例1: writeCentralDirectory

bool ZipArchive::writeCentralDirectory(std::ofstream& ofs,
                                       const std::vector<ZipArchive::ArchivedFile>& files)
{
    std::streampos offsetCD = ofs.tellp();
    size_t sizeCD = 0;
    bool error = false;
    for (size_t i = 0; i < files.size(); ++i) {
        const ZipFileHeader& fileHeader = files[i].zipFileHader_;
        ofs.write(reinterpret_cast<const char*>(&fileHeader), SIZE_ZIPFILEHEADER);
        sizeCD += SIZE_ZIPFILEHEADER;
        error = ofs.fail();

        size_t stringSize = files[i].fileName_.size();
        sizeCD += stringSize;
        if ((error == false) && (stringSize > 0) && (stringSize == fileHeader.filenameLength)) {
            ofs.write(files[i].fileName_.c_str(), stringSize);
            error = ofs.fail();
        }

        stringSize = files[i].fileExtra_.size();
        sizeCD += stringSize;
        if ((error == false) && (stringSize > 0) && (stringSize == fileHeader.extraFieldLength)) {
            ofs.write(files[i].fileExtra_.c_str(), stringSize);
            error = ofs.fail();
        }

        stringSize = files[i].fileComment_.size();
        sizeCD += stringSize;
        if ((error == false) && (stringSize > 0) && (stringSize == fileHeader.fileCommentLength)) {
            ofs.write(files[i].fileComment_.c_str(), stringSize);
            error = ofs.fail();
        }

        if (error == true) {
            LERROR("writeCentralDirectory(): failed to write Central Directory Entry in zip archive!");
            break;
        }
    }   // for

    ZipEOCDHeaderRecord eocd;
    eocd.signature = SIGNATURE_ZIPEOCDHEADERRECORD;
    eocd.numberOfDisk = 0;
    eocd.numberOfDiskWithStartOfCD = 0;
    eocd.numberOfEntriesInThisCD = static_cast<uint16_t>(files.size());
    eocd.numberOfEntriesInCD = static_cast<uint16_t>(files.size());
    eocd.sizeOfCD = static_cast<uint32_t>(sizeCD);
    eocd.offsetStartCD = (offsetCD >= 0) ? static_cast<uint32_t>(offsetCD) : 0;
    eocd.commmentLength = 0;

    if (error == false) {
        ofs.write(reinterpret_cast<char*>(&eocd), SIZE_ZIPEOCDRECORD);
        error = ofs.fail();
    }

    return (! error);
}
开发者ID:151706061,项目名称:Voreen,代码行数:56,代码来源:ziparchive.cpp

示例2: write_pixels

void cineon_writer_t::write_pixels( std::ofstream& out, const image::const_image_view_t& view) const
{
    std::vector<boost::uint32_t> buffer( view.width());

    for( int y = 0; y < view.height(); ++y)
    {
		image::const_image_view_t::x_iterator src_it( view.row_begin( y));
	
		for( int x = 0; x < view.width(); ++x)
		{
			boost::uint32_t pix = 0;
	
			float r = boost::gil::get_color( *src_it, boost::gil::red_t());
			float g = boost::gil::get_color( *src_it, boost::gil::green_t());
			float b = boost::gil::get_color( *src_it, boost::gil::blue_t());
	
			boost::uint32_t ri = adobe::clamp( r, 0.0f, 1.0f) * 1023;
			boost::uint32_t gi = adobe::clamp( g, 0.0f, 1.0f) * 1023;
			boost::uint32_t bi = adobe::clamp( b, 0.0f, 1.0f) * 1023;
			pix = ( ri << 22) | ( gi << 12) | ( bi << 2);
	
			buffer[x] = IECore::asBigEndian( pix);
			++src_it;
		}
	
		// write vector
		out.write( reinterpret_cast<char *>( &buffer[0]), view.width() * sizeof( boost::uint32_t));
		
		if ( out.fail())
			throw exception( "error while writting image");
    }
}
开发者ID:JohanAberg,项目名称:Ramen,代码行数:32,代码来源:cineon_writer.cpp

示例3: sizeof

/*---------------------------------------------------------*/
bool NOMAD::Cache_File_Point::write(std::ofstream &fout) const
{
    // do nothing if no point:
    if (_n <= 0)
        return true;

    // 1. _eval_status:
    fout.write((char *) &_eval_status , sizeof(_eval_status));

    // 2. _n:
    fout.write((char *) &_n           , sizeof(_n));

    // 3. _m:
    fout.write((char *) &_m           , sizeof(_m));

    // 4. _m_def:
    fout.write((char *) &_m_def       , sizeof(_m_def));

    // 5. _coords:
    fout.write((char *)  _coords      , _n*sizeof(double));

    if (_m_def > 0)
    {

        // 6. _bbo_def:
        fout.write((char *)  _bbo_def   , _m_def*sizeof(double));

        // 7. _bbo_index:
        fout.write((char *)  _bbo_index , _m_def*sizeof(int));
    }

    return !fout.fail();
}
开发者ID:TheLoutre,项目名称:nomad,代码行数:34,代码来源:Cache_File_Point.cpp

示例4: openOutputFile

void openOutputFile(std::ofstream& s, std::string path){
  s.open(path);
  if(s.fail()){
    std::cerr << "Failure opening file \"" << path << "\" for output." << std::endl;
    exit(0);
  }
}
开发者ID:bfisch02,项目名称:csax_cpp,代码行数:7,代码来源:io.cpp

示例5: write

bool File::write(std::ofstream& stream)
{
  CwdGuard cg(physical_dir_);
  stream.open(ACE_TEXT_ALWAYS_CHAR(physical_file_.c_str()),
              ios::binary | ios::out);
  return !stream.bad() && !stream.fail();
}
开发者ID:binary42,项目名称:OCI,代码行数:7,代码来源:FileSystemStorage.cpp

示例6: redirect_cout

bool redirect_cout (const std::string& fn)
{
	static std::ofstream alt_cout;
	alt_cout.open (fn.c_str(), std::ios::out | std::ios::binary);
	if (alt_cout.fail() ) return false;
	std::cout.rdbuf (alt_cout.rdbuf() );
	return true;
}
开发者ID:frankwz,项目名称:codecrypt,代码行数:8,代码来源:iohelpers.cpp

示例7: openFileDialog

std::string openFileDialog(std::ofstream& stream,
                           const std::string& title,
                           const std::string& path) {
    std::string filename = pp->file_openFileDialog(title, "save", path);
    if (filename == "") return "";
    stream.open(filename.c_str());
    return (stream.fail()) ? "" : filename;
}
开发者ID:mahmoudmheisen91,项目名称:Programing_Abstractions,代码行数:8,代码来源:filelib.cpp

示例8: write

int Path::write(std::ofstream &out, std::string &msg)
{
	short record_size;

	record_size = 4;
	writeShort(out, record_size);
	writeByte(out, PATH);
	writeByte(out, NoData);

	record_size = 6;
	writeShort(out, record_size);
	writeByte(out, EFLAGS);
	writeByte(out, Integer_2);
	writeShort(out, Eflags);

	record_size = 6;
	writeShort(out, record_size);
	writeByte(out, LAYER);
	writeByte(out, Integer_2);
	writeShort(out, Layer);

	record_size = 6;
	writeShort(out, record_size);
	writeByte(out, DATATYPE);
	writeByte(out, Integer_2);
	writeShort(out, Data_type);

	record_size = 8;
	writeShort(out, record_size);
	writeByte(out, WIDTH);
	writeByte(out, Integer_4);
	writeInteger(out, Width);

	record_size = 6;
	writeShort(out, record_size);
	writeByte(out, PATHTYPE);
	writeByte(out, Integer_2);
	writeShort(out, Path_type);

    record_size = 4 + short(8 * Pts.size());
	writeShort(out, record_size);
	writeByte(out, XY);
	writeByte(out, Integer_4);
	for (auto p : Pts)
	{
		writeInteger(out, p.x);
		writeInteger(out, p.y);
	}

	record_size = 4;
	writeShort(out, record_size);
	writeByte(out, ENDEL);
	writeByte(out, NoData);

	return out.fail() ? FILE_ERROR : 0;
}
开发者ID:billowen,项目名称:cgds,代码行数:56,代码来源:path.cpp

示例9: open

void _LogAppenderBase::open()
{
  if (out.is_open())
    {
      return;
    }

  makeLogDir();

  out.open(context.path.c_str(), std::fstream::out | std::fstream::app);
  if (out.fail())
    {
      out.open(context.path.c_str(), std::fstream::out | std::fstream::app);
      if (out.fail())
        {
          throw LOG_ER_OPEN;
        }
    }
}
开发者ID:gitpan,项目名称:DBD-Cubrid,代码行数:19,代码来源:cci_log.cpp

示例10:

void 
OpenOFile(std::ofstream& fs, const char* filenm)
{
  using namespace std;

  fs.open(filenm, ios::out | ios::trunc);
  if (!fs.is_open() || fs.fail()) {
    DIAG_Throw("Cannot open file '" << filenm << "'");
  }
}
开发者ID:HPCToolkit,项目名称:hpctoolkit,代码行数:10,代码来源:IOUtil.cpp

示例11: getLogStream

int FileManagement::getLogStream(std::ofstream& logStream) {
    log = logFileName + "/" + fname;
    fullPath = log + ".debug";
    logStream.open(log.c_str(), ios::app);
    if (logStream.fail()) {
        return errno;
    } else {
        chmod(log.c_str(), (mode_t) 0644);
        return 0;
    }
}
开发者ID:ic-hep,项目名称:emi3,代码行数:11,代码来源:file_management.cpp

示例12:

 /*
 * Open an ofstream with fully specified path and mode.
 */
 void
 FileMaster::open(const std::string& name, std::ofstream& out,
                  std::ios_base::openmode mode) const
 {
    out.open(name.c_str(), mode);
    if (out.fail()) {
       std::string message = "Error opening output file. Filename: ";
       message += name;
       UTIL_THROW(message.c_str());
    }
 }
开发者ID:TaherGhasimakbari,项目名称:simpatico,代码行数:14,代码来源:FileMaster.cpp

示例13: laod

/*!
   Save an homography in a file.
   The laod() function allows then to read and set the homography from this file.

   \sa load()
 */
void
vpHomography::save(std::ofstream &f) const
{
  if (! f.fail())
  {
    f << *this ;
  }
  else
  {
    throw(vpException(vpException::ioError, "Cannot write the homography to the output stream")) ;
  }
}
开发者ID:DaikiMaekawa,项目名称:visp,代码行数:18,代码来源:vpHomography.cpp

示例14: openStreamInto

 void openStreamInto( Ptr<Config> const& config, std::ofstream& ofs ) {
     // Open output file, if specified
     if( !config->getFilename().empty() ) {
         ofs.open( config->getFilename().c_str() );
         if( ofs.fail() ) {
             std::ostringstream oss;
             oss << "Unable to open file: '" << config->getFilename() << "'";
             throw std::domain_error( oss.str() );
         }
         config->setStreamBuf( ofs.rdbuf() );
     }
 }
开发者ID:JorySchossau,项目名称:Empirical,代码行数:12,代码来源:catch_session.hpp

示例15: load

/*!

  Save the pose vector in the output file stream.

  \param f : Output file stream. Should be open before entering in this method.

  \exception vpException::ioError : If the output stream is not open.

  \sa load()
*/
void
vpPoseVector::save(std::ofstream &f) const
{
  if (! f.fail())
    {
      f << *this ;
    }
  else
    {
      vpERROR_TRACE("\t\t file not open " );
      throw(vpException(vpException::ioError, "\t\t file not open")) ;
    }
}
开发者ID:tswang,项目名称:visp,代码行数:23,代码来源:vpPoseVector.cpp


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