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


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

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


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

示例1: WritePicData

bool WritePicData (std::ofstream &fdata, dirac_encoder_t *encoder)
{
    dirac_sourceparams_t &sparams = encoder->enc_ctx.src_params;
    dirac_framebuf_t &fbuf = encoder->dec_buf;
    bool ret_stat = true;

    if (encoder->decoded_frame_avail)
    {
        ios::iostate oldExceptions = fdata.exceptions();
        fdata.exceptions (ios::failbit | ios::badbit);
        try
        {
            assert (fbuf.buf[0] != 0);
            fdata.write ((char *)fbuf.buf[0], sparams.width*sparams.height);
            assert (fbuf.buf[1] != 0);
            assert (fbuf.buf[2] != 0);
            fdata.write ((char *)fbuf.buf[1],
            sparams.chroma_width*sparams.chroma_height);
            fdata.write ((char *)fbuf.buf[2],
            sparams.chroma_width*sparams.chroma_height);
        }
        catch (...)
        {
            std::cout << "Incomplete frame " << std::endl;
            ret_stat = false;
        }
        fdata.exceptions (oldExceptions);
    }
    return ret_stat;
}
开发者ID:cheeyeo,项目名称:dirac,代码行数:30,代码来源:encmain.cpp

示例2: WriteDiagnosticsHeader

bool WriteDiagnosticsHeader (std::ofstream &fdata, dirac_encoder_t *encoder)
{
    bool ret_stat = true;
    dirac_sourceparams_t &srcparams = encoder->enc_ctx.src_params;
    ios::iostate oldExceptions = fdata.exceptions();
    fdata.exceptions (ios::failbit | ios::badbit);

    try
    {
        fdata << srcparams.chroma << std::endl;
        fdata << srcparams.width << std::endl;
        fdata << srcparams.height << std::endl;
        fdata << srcparams.source_sampling << std::endl;
        fdata << srcparams.topfieldfirst << std::endl;
        fdata << srcparams.frame_rate.numerator << std::endl;
        fdata << srcparams.frame_rate.denominator << std::endl;
        fdata << srcparams.pix_asr.numerator << std::endl;
        fdata << srcparams.pix_asr.denominator << std::endl;
        fdata << encoder->enc_ctx.enc_params.picture_coding_mode << std::endl;
    }

    catch (...)
    {
        std::cerr << "Error writing sequence info in diagnostics file." << std::endl;
        ret_stat =  false;
    }
    fdata.exceptions (oldExceptions);
    return ret_stat;
}
开发者ID:cheeyeo,项目名称:dirac,代码行数:29,代码来源:encmain.cpp

示例3: createLogFile

    static std::string createLogFile(std::string suffix, std::ofstream& flog)
    {
        std::string filepath = getLogFileNamePath("log_", suffix, ".tsv", true);
        createTextFile(filepath, flog);

        Utils::log(Utils::stringf("log file started: %s", filepath.c_str()));
        flog.exceptions(flog.exceptions() | std::ios::failbit | std::ifstream::badbit);
        return filepath;
    }
开发者ID:Nakul,项目名称:AirSim,代码行数:9,代码来源:FileSystem.hpp

示例4: createLogFile

    static std::string createLogFile(const std::string& suffix, std::ofstream& flog)
    {
        std::string log_folderpath = common_utils::FileSystem::getLogFolderPath(false);
        std::string filepath = getLogFileNamePath(log_folderpath, "log_", suffix, ".tsv", true);
        createTextFile(filepath, flog);

        Utils::log(Utils::stringf("log file started: %s", filepath.c_str()));
        flog.exceptions(flog.exceptions() | std::ios::failbit | std::ifstream::badbit);
        return filepath;
    }
开发者ID:Jinwei1,项目名称:AirSim,代码行数:10,代码来源:FileSystem.hpp

示例5: fork_controller

/**
    Forks off the controller process at a lower priority than the coordinator
    process
*/
void fork_controller() {
    // Fork the Controller
    controller_pid = fork();
    if (controller_pid < 0) {
        throw std::runtime_error( "Failed to fork controller." ) ;
    }
    if (controller_pid == 0) {
        controller_pid = getpid();
        int priority_result = setpriority( PRIO_PROCESS, controller_pid, sim_priority + 1 );
        int controller_priority = getpriority( PRIO_PROCESS, controller_pid );

        //controller_log.exceptions( std::ofstream::failbit | std::ofstream::badbit );
        controller_log.exceptions( std::ofstream::failbit );

        try {
            controller_log.open("controller.log");
        } catch (std::ofstream::failure ex) {
            printf( "FAILED TO OPEN STREAM.\n" );  // Likely won't print to console
        }

//        if( !controller_log.is_open() )
        //            printf( "FAILED TO OPEN STREAM.\n" );

        if( priority_result < 0 ) {
            controller_log << "ERROR: Failed to set priority: " << priority_result << "\n";
        } else {
            controller_log << "Controller PID: " << controller_pid << "\n";
            controller_log << "Controller Priority: " << controller_priority << "\n";
        }


        controller();
    }
}
开发者ID:semajrolyat,项目名称:tas,代码行数:38,代码来源:proto_sim.cpp

示例6: fork_controller

void fork_controller() {

    controller_pid = fork();
    if (controller_pid < 0) {
        throw std::runtime_error( "Failed to fork controller." ) ;
    }
    if (controller_pid == 0) {
        controller_pid = getpid();

        int priority_result = setpriority( PRIO_PROCESS, controller_pid, sim_priority + 1 );
        int controller_priority = getpriority( PRIO_PROCESS, controller_pid );

        controller_log.exceptions( std::ofstream::failbit );

        try {
            controller_log.open("controller.log");
        } catch (std::ofstream::failure ex) {
            printf( "FAILED TO OPEN STREAM.\n" );  // Likely won't print to console
        }

        if( priority_result < 0 ) {
            controller_log << "ERROR: Failed to set priority: " << priority_result << "\n";
        } else {
            controller_log << "Controller PID: " << controller_pid << "\n";
            controller_log << "Controller Priority: " << controller_priority << "\n";
        }

        // execute the controller program
        execl( "controller", "contoller", 0 );

        // exit on fail to exec
        _exit(1);
    }
}
开发者ID:gparmer,项目名称:tas,代码行数:34,代码来源:proto_threading.cpp

示例7: open

 void open(const std::string& a_fname, bool a_append = false) {
     using std::ios;
     using std::ios_base;
     if (m_open) return;
     m_file.exceptions(ios::failbit | ios::badbit);
     ios_base::openmode l_mode = ios::out | ios::binary;
     if (a_append)
         l_mode |= ios::app;
     else
         l_mode |= ios::trunc;
     m_file.open(a_fname.c_str(), l_mode);
     m_offset = m_file.tellp();
     m_open = true;
     m_fname = a_fname;
     m_buf.reset();
     BOOST_ASSERT(m_buf.capacity() > 0);
 }
开发者ID:saleyn,项目名称:utxx,代码行数:17,代码来源:file_writer.hpp

示例8: Open

	void Log::Open(auto dir, LogMode mode) {
#ifdef LOG
		// format date and time
		char date[32];
		time_t sec = time(nullptr);
		struct tm * loctime = localtime(&sec);
		strftime(date, 32, "%m-%d_%H-%M-%S", loctime);

		// create temperary strings
		this->dir = std::string(dir);
		std::string datestr = std::string(date);

		// add path separator if necessary
		if(this->dir[this->dir.length() - 1] != PATH_SEP) {
			this->dir += PATH_SEP;
		}

		// add directory for log and images if necessary
		if(mode == LogMode::Multi) this->dir += datestr + PATH_SEP;

		int ret = mkdir(this->dir.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP
				| S_IROTH | S_IWOTH | S_IXUSR | S_IXGRP
				| S_IXOTH);

		filename = this->dir + datestr + ".log";

		// set class mode
		this->mode = mode;

		// Initializing file
		file.exceptions(std::ofstream::failbit
				| std::ofstream::badbit);

		try {
			file.open(filename, std::ofstream::out
					| std::ofstream::app);
		} catch(std::ofstream::failure ex) {
			LogError("Oh, no! An error has occurred opening the "
					"log file.", ex);
		}
#endif
	}
开发者ID:sawbg,项目名称:chip-chip-array,代码行数:42,代码来源:Log.hpp

示例9: OpenOutputStream

void WindowsFileOpener::OpenOutputStream( std::ofstream &stream, std::ios_base::openmode openModeRequired )
{
	stream.exceptions( std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit );
	stream.open( _filePath.c_str(), openModeRequired );
}
开发者ID:jonathan-markland,项目名称:Jynx,代码行数:5,代码来源:WindowsFileOpener.cpp

示例10: WriteDiagnosticsData

bool WriteDiagnosticsData (std::ofstream &fdata, dirac_encoder_t *encoder)
{
    dirac_instr_t &instr = encoder->instr;
    bool ret_stat = true;

    if (encoder->instr_data_avail)
    {
        ios::iostate oldExceptions = fdata.exceptions();
        fdata.exceptions (ios::failbit | ios::badbit);
        try
        {
            fdata << std::endl << "[frame:" << instr.pnum << "]";
            if (instr.ptype == INTRA_PICTURE)
            {
                fdata << ">intra" << std::endl;
                return true;
            }

            fdata << ">mo_comp";
            fdata << std::endl << std::endl << instr.num_refs << " ";
            for (int i=0; i<instr.num_refs; ++i)
            {
                fdata << instr.refs[i] << " ";
            }
            fdata << instr.ybsep << " " << instr.xbsep << " ";
            fdata << instr.sb_ylen << " " << instr.sb_xlen << " ";
            fdata << instr.mv_ylen << " " << instr.mv_xlen
                    << std::endl << std::endl ;
            for (int j=0; j<instr.sb_ylen; j++)
            {
                for (int i=0; i<instr.sb_xlen; i++)
                    fdata << instr.sb_split_mode[j*instr.sb_xlen + i] << " ";
                fdata << std::endl;
            }
            fdata << std::endl;

            for (int j=0; j<instr.sb_ylen; j++)
            {
                for (int i=0; i<instr.sb_xlen; i++)
                    fdata << instr.sb_costs[j*instr.sb_xlen + i] << " ";
                fdata << std::endl;
            }
            fdata << std::endl;

            for (int j=0; j<instr.mv_ylen; j++)
            {
                for (int i=0; i<instr.mv_xlen; i++)
                    fdata << instr.pred_mode[j*instr.mv_xlen + i] << " ";
                fdata << std::endl;
            }
            fdata << std::endl;

            for (int j=0; j<instr.mv_ylen; j++)
            {
                for (int i=0; i<instr.mv_xlen; i++)
                    fdata << instr.intra_costs[j*instr.mv_xlen + i] << " ";
                fdata << std::endl;
            }
            fdata << std::endl;

            if (instr.num_refs > 1)
            {
                for (int j=0; j<instr.mv_ylen; j++)
                {
                    for (int i=0; i<instr.mv_xlen; i++)
                    {
                        fdata << instr.bipred_costs[j*instr.mv_xlen + i].SAD
                        <<" " << instr.bipred_costs[j*instr.mv_xlen + i].mvcost
                        << " ";;
                    }
                    fdata << std::endl;
                }
            }
            fdata << std::endl;

            for (int j=0; j<instr.mv_ylen; j++)
            {
                for (int i=0; i<instr.mv_xlen; i++)
                    fdata << instr.dc_ycomp[j*instr.mv_xlen + i] << " ";
                fdata << std::endl;
            }

            // FIXME: always expects 3 components
            fdata << std::endl;
            for (int j=0; j<instr.mv_ylen; j++)
            {
                for (int i=0; i<instr.mv_xlen; i++)
                    fdata << instr.dc_ucomp[j*instr.mv_xlen + i] << " ";
                fdata << std::endl;
            }
            fdata << std::endl;
            for (int j=0; j<instr.mv_ylen; j++)
            {
                for (int i=0; i<instr.mv_xlen; i++)
                    fdata << instr.dc_vcomp[j*instr.mv_xlen + i] << " ";
                fdata << std::endl;
            }

            for (int k = 0; k < instr.num_refs; k++)
            {
//.........这里部分代码省略.........
开发者ID:cheeyeo,项目名称:dirac,代码行数:101,代码来源:encmain.cpp

示例11: start_table

void start_table(std::ofstream &ostr, std::string &filename, bool for_instructor,
                 const std::vector<Student*> &students, int rank, int month, int day, int year) {
  
  ostr.exceptions ( std::ofstream::failbit | std::ofstream::badbit );
  try {
    ostr.open(filename.c_str());
  }
  catch (std::ofstream::failure e) {
    std::cout << "FAILED TO OPEN " << filename << std::endl;
    std::cerr << "Exception opening/reading file";
    exit(0);
  }

  Student* s = NULL;
  if (rank != -1) {
    s = students[rank];
    assert (s != NULL);
  }


  // -------------------------------------------------------------------------------
  // PRINT INSTRUCTOR SUPPLIED MESSAGES
  for (int i = 0; i < MESSAGES.size(); i++) {
    ostr << "" << MESSAGES[i] << "<br>\n";
  }
  // get todays date
  //time_t now = time(0);  
  //struct tm * now2 = localtime( & now );
  if (s != NULL) {
    ostr << "<em>Information last updated: " << s->getLastUpdate() << "</em><br>\n";
  }
  ostr << "<p>&nbsp;</p>\n";


  ostr << "<p>&nbsp;</p>\n";

  // -------------------------------------------------------------------------------
  // BEGIN THE TABLE
  ostr << "<table border=2 cellpadding=5 cellspacing=0>\n";

  // open the title row
  ostr << "<tr>";


  // -------------------------------------------------------------------------------
  // RANK & SECTION
  if (for_instructor) {
    ostr << "<td align=center>#</td>";   
  }
  ostr << "<td align=center>SECTION</td>";   
  
  // -------------------------------------------------------------------------------
  // INSTRUCTOR NOTES
  if (for_instructor && DISPLAY_INSTRUCTOR_NOTES) {
    ostr << "<td align=center>part.</td>" 
         << "<td align=center>under.</td>";
    ostr << "<td align=center>notes</td>";
  }

  
  // -------------------------------------------------------------------------------  
  // NAME
  ostr << "<td align=center>USERNAME</td>";
  ostr << "<td align=center>LAST</td>" 
       << "<td align=center>FIRST</td>";
  
  // -------------------------------------------------------------------------------  
  // EXAM SEATING
  if (DISPLAY_EXAM_SEATING) {
    ostr << "<td align=center bgcolor=888888>&nbsp;</td>";
    ostr << "<td align=center>exam room</td>";
    ostr << "<td align=center>exam zone</td>";
    ostr << "<td align=center>exam time</td>";
  }

  // -------------------------------------------------------------------------------  
  // ICLICKER REMOTE
  if (DISPLAY_ICLICKER && ICLICKER_QUESTION_NAMES.size() > 0) {
    ostr << "<td align=center>iclicker status</td>";
  }

  // -------------------------------------------------------------------------------  
  // GRADE SUMMARY
  if (DISPLAY_GRADE_SUMMARY) {
    if (DISPLAY_FINAL_GRADE) {
      ostr << "<td align=center bgcolor=888888>&nbsp;</td>";
      ostr << "<td align=center>GRADE</td>";
    }
    ostr << "<td align=center bgcolor=888888>&nbsp;</td>";
    ostr << "<td align=center>OVERALL</td>";
    if (for_instructor && DISPLAY_MOSS_DETAILS) {
      ostr << "<td align=center>OVERALL W/ MOSS PENALTY</td>";
      ostr << "<td align=center>GRADE BEFORE MOSS</td>";
    }
    ostr << "<td align=center bgcolor=888888>&nbsp;</td>";
    for (int i = 0; i < ALL_GRADEABLES.size(); i++) {
      ostr << "<td align=center>" << gradeable_to_string(ALL_GRADEABLES[i]) << " %</td>";
    }
  }

//.........这里部分代码省略.........
开发者ID:chuck211991,项目名称:HWserver,代码行数:101,代码来源:output.cpp


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