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


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

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


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

示例1: 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

示例2: LogLastError

void LogLastError()
{
	if (!ofs.bad())
	{
		DWORD eNum = GetLastError();
		TCHAR sysMsg[256];
		if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, eNum,
			MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), sysMsg, 256, NULL) == 0)
		{
			Log("ERROR | LogLastError | Couldn't format error message with number", eNum, true);
			return;
		}

		// find end of string
		TCHAR *p = sysMsg;
		while ((*p > 31) || (*p == 9))
		{
			++p;
		}

		// remove unused end
		do
		{
			*p-- = 0;
		} while ((p >= sysMsg) && ((*p == '.') || (*p < 33)));

		Log("      | GetLastError |", sysMsg);
	}
}
开发者ID:Hybris95,项目名称:LolSceneSwitch,代码行数:29,代码来源:Log.cpp

示例3: Log

void Log(_In_ char const * text)
{
	if (!ofs.bad())
	{
		ofs << text << std::endl;
	}
}
开发者ID:Hybris95,项目名称:LolSceneSwitch,代码行数:7,代码来源:Log.cpp

示例4: write_data

/* Writes the grid of values of an EM map to a MRC file */
void MRCReaderWriter::write_data(std::ofstream &s,const float *pt)
{

  s.write((char *)pt,sizeof(float)*header.nx * header.ny * header.nz);
  IMP_USAGE_CHECK(!s.bad(),
            "MRCReaderWriter::write_data >> Error writing MRC data.");
  IMP_LOG(TERSE,"MRC file written: grid " << header.nx << "x" << header.ny
          << "x" << header.nz << std::endl);
}
开发者ID:andreyto,项目名称:imp-fork-proddl,代码行数:10,代码来源:MRCReaderWriter.cpp

示例5: create_tmpfile

//----------------------------------------------------------------------------------
// Opens a temporary file
std::string Gnuplot::create_tmpfile(std::ofstream &tmp)
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
    char name[] = "gnuplotiXXXXXX"; //tmp file in working directory
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
    char name[] = "/tmp/gnuplotiXXXXXX"; // tmp file in /tmp
#endif

    // check if maximum number of temporary files reached
    if (Gnuplot::tmpfile_num == GP_MAX_TMP_FILES - 1)
    {
        std::ostringstream except;
        except << "Maximum number of temporary files reached (" << GP_MAX_TMP_FILES
               << "): cannot open more files" << std::endl;

        throw GnuplotException( except.str() );
        return "";
    }

    // int mkstemp(char *name);
    // shall replace the contents of the string pointed to by "name" by a unique filename,
    // and return a file descriptor for the file open for reading and writing.
    // Otherwise, -1 shall be returned if no suitable file could be created.
    // The string in template should look like a filename with six trailing 'X' s;
    // mkstemp() replaces each 'X' with a character from the portable filename character set.
    // The characters are chosen such that the resulting name does not duplicate the name of an existing file at the time of a call to mkstemp()


    // open temporary files for output
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
		if (_mktemp(name) == nullptr)
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
    if (mkstemp(name) == -1)
#endif
    {
        std::ostringstream except;
        except << "Cannot create temporary file \"" << name << "\"";
        throw GnuplotException(except.str());
        return "";
    }

    tmp.open(name);
    if (tmp.bad())
    {
        std::ostringstream except;
        except << "Cannot create temporary file \"" << name << "\"";
        throw GnuplotException(except.str());
        return "";
    }

    // Save the temporary filename
    this->tmpfile_list.push_back(name);
    Gnuplot::tmpfile_num++;

    return name;
}
开发者ID:ldsc,项目名称:lib_ldsc,代码行数:58,代码来源:CGnuplot.cpp

示例6: throw

template <class T> inline void exec_output(T reg, int which_byte){
  union {
    char byte[4];
    T word;
  } tmp;

  tmp.word = reg;
  fout.write(tmp.byte + which_byte, 1);
  if( fout.bad() ) {
    throw (std::string)"fatal Error:データ読み込みエラー";
  }
  return;
}
开发者ID:cpumul4,项目名称:cpuex,代码行数:13,代码来源:io.hpp

示例7: tempfile

// Creates a temporary file
std::string Plot::tempfile(std::ofstream &out)
{
	std::string path;
	sys::fs::mkstemp(&path);

	out.open(path.c_str());
	if (out.bad()) {
		throw PEX(str::printf("Unable to open temporary file '%s'", path.c_str()));
	}

	m_tempfiles.push_back(path);
	return path;
}
开发者ID:ashang,项目名称:pepper,代码行数:14,代码来源:plot.cpp

示例8: write

bool compactIntArray::write(std::ofstream& fout)
{
    fout.write((char*)&size, sizeof(size));
    fout.write((char*)&wordsize, sizeof(wordsize));
    fout.write((char*)&innersize, sizeof(innersize));

    fout.write((char*)array, sizeof(*array) * innersize);
    if(fout.bad())
    {
        return false;
    }
    else
    {
        return true;
    }
}
开发者ID:bluecliff,项目名称:CSA,代码行数:16,代码来源:compactIntArray.cpp

示例9: inicializarSharedObjects

void inicializarSharedObjects(CajaRegistradora& caja, Grilla& grilla, GrillaJefe& grillaJefe, Surtidores& surtidores,
		unsigned int cantEmpleados, unsigned int cantSurtidores,
		std::ofstream& archivoColaInputJefe, ColaConPrioridad<automovil>& colaAutosJefe) {
	caja.inicializarCaja();
	grilla.inicializarGrilla(cantEmpleados);
	grillaJefe.inicializarGrillaJefe();
	surtidores.inicializarSurtidores(cantSurtidores);

	if (archivoColaInputJefe.fail() || archivoColaInputJefe.bad()) {
		std::string me = __FILE__ ":inicializarSharedObjects";
		std::string _msg = std::string("Error creando archivo para la cola entre el jefe y el input: ") + std::string(strerror(errno));
		Logger::error(_msg, me);
		throw _msg;
	}
	// TODO: Ordenar la creacion de esta cola. Encapsularlo porque queda feito
	colaAutosJefe = ColaConPrioridad<automovil> ( colaInputJefe, colaInputJefeKey );

}
开发者ID:SebastianBogado,项目名称:7559-tp-concu-2014-1c,代码行数:18,代码来源:estacion.cpp

示例10: write_header

void MRCReaderWriter::write_header(std::ofstream &s)
{
  header.ispg = 1065353216;
  memcpy(header.map, "MAP ", 4);
  //  header.machinestamp = get_machine_stamp();
  int wordsize=4;
  s.write((char *) &header.nx,wordsize);
  s.write((char *) &header.ny,wordsize);
  s.write((char *) &header.nz,wordsize);
  s.write((char *) &header.mode,wordsize);
  s.write((char *) &header.nxstart,wordsize);
  s.write((char *) &header.nystart,wordsize);
  s.write((char *) &header.nzstart,wordsize);
  s.write((char *) &header.mx,wordsize);
  s.write((char *) &header.my,wordsize);
  s.write((char *) &header.mz,wordsize);
  s.write((char *) &header.xlen,wordsize);
  s.write((char *) &header.ylen,wordsize);
  s.write((char *) &header.zlen,wordsize);
  s.write((char *) &header.alpha,wordsize);
  s.write((char *) &header.beta,wordsize);
  s.write((char *) &header.gamma,wordsize);
  s.write((char *) &header.mapc,wordsize);
  s.write((char *) &header.mapr,wordsize);
  s.write((char *) &header.maps,wordsize);
  s.write((char *) &header.dmin,wordsize);
  s.write((char *) &header.dmax,wordsize);
  s.write((char *) &header.dmean,wordsize);
  s.write((char *) &header.ispg,wordsize);
  s.write((char *) &header.nsymbt,wordsize);
  s.write((char *) &header.user,wordsize*IMP_MRC_USER);
  s.write((char *) &header.xorigin,wordsize);
  s.write((char *) &header.yorigin,wordsize);
  s.write((char *) &header.zorigin,wordsize);
  s.write((char *) &header.map,wordsize);
  s.write((char *) &header.machinestamp,wordsize);
  s.write((char *) &header.rms,wordsize);
  s.write((char *) &header.nlabl,wordsize);
  s.write((char *) &header.labels,
          sizeof(char)*IMP_MRC_NUM_LABELS*IMP_MRC_LABEL_SIZE);
  IMP_USAGE_CHECK(!s.bad(),
            "MRCReaderWriter::write_header >> Error writing MRC header");
}
开发者ID:andreyto,项目名称:imp-fork-proddl,代码行数:43,代码来源:MRCReaderWriter.cpp

示例11: fstreamWriteBig

void fstreamWriteBig(std::ofstream &S, char* A, unsigned long long N, std::string fileName, std::string errorID, Parameters *P) {

    struct statvfs statvfsBuf;
    statvfs(fileName.c_str(), &statvfsBuf);
    P->inOut->logMain << "Writing " << N << " bytes into " <<fileName << " ; empty space on disk = " << statvfsBuf.f_bavail * statvfsBuf.f_bsize <<" bytes ..." <<flush;
    
    unsigned long long C=0;
    unsigned long long iC;
    for (iC=0; iC<N/fstream_Chunk_Max; iC++) {
        S.write(A+C,fstream_Chunk_Max);
        C+=fstream_Chunk_Max;
    };
    if (!S.fail()) S.write(A+C,N%fstream_Chunk_Max);
    if (S.fail()) {//failed to write

        struct statvfs statvfsBuf;
        statvfs(fileName.c_str(), &statvfsBuf);
    
//         system(( "ls -lL "+ P->genomeDir + " > "+ P->genomeDir +"/error.info 2>&1").c_str());
//         ifstream error_info((P->genomeDir +"/error.info").c_str());
//         P->inOut->logMain <<error_info.rdbuf();
        
        struct stat statBuf;
        stat(fileName.c_str(), &statBuf);
        
        remove(fileName.c_str());
        
        ostringstream errOut;
        errOut << errorID<<": exiting because of *OUTPUT FILE* error: could not write the output file "<< fileName <<"\n";
        errOut << "fail()=" <<S.fail() <<" ; bad()="<< S.bad()<<"\n";
        errOut << "Error while trying to write chunk # " << iC << "; "<< C << " bytes\n";
        errOut << "File size full = "<< N <<" bytes\n";        
        errOut << "File size on disk = " << statBuf.st_size<<" bytes\n";
        errOut << "Solution: check that you have enough space on the disk\n";
        errOut << "Empty space on disk = " << statvfsBuf.f_bavail * statvfsBuf.f_bsize <<" bytes\n";
        exitWithError(errOut.str(),std::cerr, P->inOut->logMain, EXIT_CODE_FILE_WRITE, *P);
    };
    P->inOut->logMain << " done\n" <<flush;
};
开发者ID:kellyquek,项目名称:STAR,代码行数:39,代码来源:streamFuns.cpp

示例12: write

 virtual bool write(std::ofstream& out, int n, int groups, bool binary)
 {
     if (n > dataSize && !data) return false;
     if (binary)
     {
         out.write((char*)data, n * sizeof(T));
     }
     else
     {
         if (groups <= 0 || groups > n) groups = n;
         for (int i = 0; i < n; ++i)
         {
             if ((i % groups) > 0)
                 out << ' ';
             out << data[i];
             if ((i % groups) == groups-1)
                 out << '\n';
         }
     }
     if (out.bad())
         return false;
     return true;
 }
开发者ID:fredroy,项目名称:sofa,代码行数:23,代码来源:mesh_io_vtk.cpp


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