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


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

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


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

示例1: solver_out

void solver_out (const ShExpPanel& pan, ofstream& out) throw (ShExpException)
{
  if (!out)
    throw ShExpException ("Error: bad stream for results output.\n");

  out.exceptions (ios_base:: badbit | ios_base:: failbit);
  out << scientific << setprecision (6);
  try
    {
      out << "\nPanel: " << pan.id() << endl;
      out << "----------------------------------------\n";
      out << "Mach number:          " << setw(15) << pan.mach() << endl;
      out << "pressure:             " << setw(15) << pan.p() << " [Pa]\n";
      out << "pressure coefficient: " << setw(15) << pan.cp() << endl;
      out << "density:              " << setw(15) << pan.ro() << " [kg*m^-3]\n";
      out << "temperature:          " << setw(15) << pan.t() << " [K]\n";
      out << "velocity:             " << setw(15) << pan.vel() << " [m*s^-2]\n";
      out << "velocity u:           " << setw(15) << pan.u() << " [m*s^-2]\n";
      out << "velocity v:           " << setw(15) << pan.v() << " [m*s^-2]\n";
      out << "local speed of sound: " << setw(15) << pan.a() << " [m*s^-2]\n";
      out << "----------------------------------------\n";
    }
  catch (ios_base:: failure)
    {
      throw;
    }
}
开发者ID:Arktor,项目名称:shockexpansion,代码行数:27,代码来源:solver_out.cpp

示例2: CheckAndOpenFileForWriting

void CRunner::CheckAndOpenFileForWriting(ofstream & file, const string& fileName)
{
	file.open(fileName);
	file.exceptions(ofstream::badbit);
	if (!file.is_open())
	{
		throw ofstream::failure(MESSAGE_FAILED_OPEN + fileName + MESSAGE_FAILED_OPEN_FOR_WRITING);
	}
}
开发者ID:7kia,项目名称:MLaTA,代码行数:9,代码来源:Runner.cpp

示例3: openOutputFile

void openOutputFile(const string fileName, ofstream &handle){

	handle.exceptions(ofstream::failbit | ofstream::badbit);
	try{
		handle.open(fileName);
	}
	catch (const ofstream::failure &e){
		cerr << e.what() << endl;
		cerr << "File " << fileName << " cannot be opened!" << endl;
		terminate();
	}

}
开发者ID:yanpeiliu,项目名称:SleepScale,代码行数:13,代码来源:Server.cpp

示例4: vcamOpenLog

void __stdcall vcamOpenLog(int verbosity, char* message)
{
#ifdef _DEBUG
	{
		CAutoLock l(&debugLock);
		if (numUsers == 0) {
			BOOL ok = CreateDirectory(VCAM_DEBUG_DIRNAME, NULL);
			if (!ok && GetLastError() == ERROR_ALREADY_EXISTS)
			{
				ok = TRUE;
			}
			if (ok) {
				try {
					debugOut.exceptions(ios::failbit);
					debugOut.open(VCAM_DEBUG_FNAME, ios_base::app);
					// Truncate log if it's too big
					debugOut.seekp(0, ios_base::end);
					if (debugOut.tellp() > 1024 * 256) {
						debugOut.close();
						debugOut.open(VCAM_DEBUG_FNAME, ios_base::trunc);
					}
					openedOK = TRUE;
				}
				catch (...)
				{
					openedOK = FALSE;
				}
			}
			else 
			{
				openedOK = FALSE;
			}
			if (!openedOK && !showedLogWarning)
			{
				Msg("Couldn't open multicam log file,\r\nso no logging will be performed");
				showedLogWarning = TRUE;
			}
		}
		numUsers++;
	}
	vcamLog(verbosity, "%s opened log, numUsers = %d", message, numUsers);
#endif
}
开发者ID:cakiem,项目名称:MultiCam,代码行数:43,代码来源:LogHelpers.cpp

示例5: parser_out

void parser_out (const ShExpPanel& pan, ofstream& out) throw (ShExpException)
{
  if (!out)
    throw ShExpException ("Error: bad stream for results output.\n");

  out.exceptions (ios_base:: badbit | ios_base:: failbit);
  out << scientific << setprecision (6);
  
  try
    {
      out << "\nPanel: " << pan.id() << endl;
      out << "----------------------------------------\n";
      out << "Node 1:       (" << pan.x1() << ":" << pan.y1() << ")\n";
      out << "Node 2:       (" << pan.x2() << ":" << pan.y2() << ")\n";
      out << "Slope:         " << setw(15) << pan.slp(RAD) << " [rad]\n";
      out << "Relative area: " << setw(15) << pan.ar() << endl;
      out << "----------------------------------------\n";
    }
  catch (ios_base:: failure)
    {
      throw;
    }
}
开发者ID:Arktor,项目名称:shockexpansion,代码行数:23,代码来源:parser_out.cpp

示例6: patchFile

int KiCadSCH::patchFile(ofstream &oFile)
{
    string iline, oline, last_oline;
    modiFile_t currentpatch;
    int line_n;
    unsigned i;
    unsigned olineNbr = 0;

    iSCHfile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
    oFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);

    try{
        last_oline = "";
        for(line_n=0; true; line_n++){
            getline(iSCHfile, iline);
            oline = iline;
            currentpatch.add = false;
            currentpatch.del = false;
            currentpatch.line = "";
            currentpatch.lineNbr = 0;
            for(i=0;i<patchvec.size();i++){
                if(line_n == patchvec[i].lineNbr){
                    currentpatch = patchvec[i];
                    patchvec[i].prevline = last_oline;
                    if(currentpatch.add){
                        oFile << currentpatch.line << endl;
                        olineNbr++;
                        patchvec[i].olineNbr = olineNbr;
                    }
                }
            }
            if(!currentpatch.del){
                oFile << oline << endl;
                last_oline = oline;
                olineNbr++;
                if(patchvec.size()>i){ // if patchvec is empty
                    patchvec[i].olineNbr = olineNbr;
                }
            }else{
                if(patchvec.size()<i) patchvec[i].deletedline = oline;
            }
        }
    }
    catch(std::fstream::failure e){
        if(iSCHfile.bad()) return -1;
        if(oFile.bad()) return -2;
        if(iSCHfile.fail()) return -1;
        if(oFile.fail()) return -2;
        if(iSCHfile.eof()){
            iSCHfile.clear();
            iSCHfile.seekg(0, ios::beg);
            return 0;
        }
        if(oFile.eof()) {
            oFile.clear();
            return -2;
        }
        return -255;
    }
    return 0;
}
开发者ID:TheTesla,项目名称:KiCadSCHpatcher,代码行数:61,代码来源:KiCadSCH.cpp


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