本文整理汇总了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);
}
示例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");
}
}
示例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();
}
示例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);
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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 << "'");
}
}
示例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;
}
}
示例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());
}
}
示例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")) ;
}
}
示例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() );
}
}
示例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")) ;
}
}