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


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

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


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

示例1: time

std::ofstream& Logger::LogStart(TLogLevel level){ 
	char buffer[64];
	
	if (logger_os.tellp() >= logger_max_file_size){
		logger_os.close();
		std::string renamed_file = logger_filename;
		renamed_file.append(".backup");
		
		if (file_exists(renamed_file.c_str())) remove (renamed_file.c_str());

		rename(logger_filename.c_str(), renamed_file.c_str());
		remove (logger_filename.c_str());
	}	

	if (!file_exists(logger_filename.c_str())){
		logger_os.close();
		logger_os.open(logger_filename.c_str(),  std::ios::out | std::ios::app);
		if (logger_os.is_open()){
			logger_messageLevel = loggger_wantedLevel;
		}else{
			logger_messageLevel = logNone; //prevent from sending data into the not opened stream
		}
	}

	time_t thetime = time(0);
	tm * ptm = std::localtime(& thetime);
	strftime(buffer, sizeof(buffer), "%d.%m.%Y %H:%M:%S", ptm);// Format: 15.06.2009 20:20:00 

	logger_os << "-" << buffer << " " << ToString(level) << ": ";

	return logger_os;
}
开发者ID:tom-2015,项目名称:rpi-geiger-counter,代码行数:32,代码来源:log.cpp

示例2: flush

void Logger::flush()
{
	if (g_logFile.is_open()) 
	{
		g_logFile.flush();
	}
}
开发者ID:rokuz,项目名称:DemoScene,代码行数:7,代码来源:logger.cpp

示例3: image_stereo_callback

/**
 * This method will be called when a new image message is published
 * We will write this information to the image folder
 * We will append the image time to the timestamp of the folder
 */
void image_stereo_callback(const sensor_msgs::ImageConstPtr& msgL,const sensor_msgs::ImageConstPtr& msgR) {
    if (!outfile_img.is_open()) {
        ROS_ERROR("Unable to open image file");
        return;
    }

    // Create our folder timestamp
    char filename[128];
    std::sprintf(filename, "img_%ld.png", msgL.get()->header.stamp.toNSec());

    // Else write the new reading to file
    outfile_img << msgL.get()->height << " "
                << msgL.get()->width << " "
                << msgL.get()->header.stamp.toNSec() << " "
                << "images_cam0/" << filename << " "
                << msgR.get()->height << " "
                << msgR.get()->width << " "
                << msgR.get()->header.stamp.toNSec() << " "
                << "images_cam1/" << filename << "\n";

    // Convert the image msg to open cv
    cv_bridge::CvImagePtr cv_ptr_l = cv_bridge::toCvCopy(msgL, "bgr8");
    cv::imwrite(folder_images_l+filename, cv_ptr_l->image);
    cv_bridge::CvImagePtr cv_ptr_r = cv_bridge::toCvCopy(msgR, "bgr8");
    cv::imwrite(folder_images_r+filename, cv_ptr_r->image);
}
开发者ID:rpng,项目名称:img_imu_record,代码行数:31,代码来源:main.cpp

示例4: log

inline void log(const char* type,const char* file,int line,void* Add)
{
    if(fichier_log.is_open())
    {
        fichier_log << type << "\t" << file << "\t" << line << "\t" << Add << std::endl;
    }
}
开发者ID:freemaul,项目名称:GefMoteur,代码行数:7,代码来源:GefDebug.hpp

示例5: close

void Logger::close(){
	if (logger_os.is_open()){
		logger_os.flush();
		logger_os.close();
		logger_messageLevel = logNone;
	}
}
开发者ID:tom-2015,项目名称:rpi-geiger-counter,代码行数:7,代码来源:log.cpp

示例6: output_mag

int output_mag(std::ofstream& ofile){
	// check calling of routine if error checking is activated
        if(err::check==true){std::cout << "grains::output_mag has been called" << std::endl;}

	// calculate grain magnetisations
	grains::mag();

		if(vmpi::my_rank==0){
		// check file stream is open
		if(!ofile.is_open()){
			terminaltextcolor(RED);
			std::cerr << "Error - file stream is unopened for grains::output_mag(), exiting!" << std::endl;
			terminaltextcolor(WHITE);
		err::vexit();
		}

		unsigned int id=0; // grain id (excluding grains with zero atoms)

		// calculate mag_m of each grain and normalised direction
		for(int grain=0;grain<grains::num_grains;grain++){
			// check for grains with zero atoms
			if(grains::grain_size_array[grain]==0){
				//std::cerr << "Warning Grain " << grain << " has no constituent atoms!" << std::endl;
			}
			else{
				ofile << grain << "\t" << id << "\t" << grains::x_mag_array[grain] << "\t" << grains::y_mag_array[grain];
				ofile << "\t" << grains::z_mag_array[grain] << "\t" << grains::mag_m_array[grain] << std::endl;
				id++;
			}
		}
	}

	return EXIT_SUCCESS;
}
开发者ID:Rory-Pond,项目名称:vampire,代码行数:34,代码来源:grains.cpp

示例7: hook_ante_loop

  void hook_ante_loop(const int nt)
  {
    parent_t::hook_ante_loop(nt);
    if (this->rank != 0) return;

    //checking what are the MPDATA options of each test simulation (fct / iga / ...) 
    //basing on gnuplot output filename ...
    std::string gnuplot_name = this->p.gnuplot_output;
    std::string name;
    char delimeter('%');
    std::istringstream iss(gnuplot_name);
    getline(iss, name, delimeter);
    // ... and naming output stats file accordingly
    if(!ofs.is_open())
      ofs.open("stats_"+name+".txt", std::ofstream::out);

    last_timestep = nt;

    true_solution.resize(this->mem->advectee().shape());
    error_2.resize(this->mem->advectee().shape());

    //after one full rotation true solution is equal to the inital state
    true_solution = this->mem->advectee();
    ofs << std::fixed << std::setprecision(8) << std::endl;
    ofs << "timestep      = 0"     << std::endl;
    ofs << "min(solution) = " << min(true_solution) <<std::endl;
    ofs << "max(solution) = " << max(true_solution) <<std::endl;
    ofs << " " <<std::endl;
  }
开发者ID:djarecka,项目名称:libmpdataxx,代码行数:29,代码来源:rotating_cone_stats.hpp

示例8:

	wesnoth_global_fixture()
	{
		reporter.open("boost_test_result.xml");
		assert( reporter.is_open() );

		boost::unit_test::results_reporter::set_stream(reporter);
//		lg::set_log_domain_severity("all",3);
		game_config::path = get_cwd();


		// Initialize unit tests
		SDL_Init(SDL_INIT_TIMER);
		test_utils::get_fake_display(1024, 768);

		gui2::init();
		static const gui2::event::tmanager gui_event_manager;



		// Set more report as default
		if (boost::unit_test::runtime_config::log_level() == boost::unit_test::invalid_log_level)
			boost::unit_test::unit_test_log.set_threshold_level( boost::unit_test::log_messages );
		if (boost::unit_test::runtime_config::report_level() == boost::unit_test::INV_REPORT_LEVEL)
			boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT);
		boost::unit_test::unit_test_monitor.register_exception_translator<game::error>(&exception_translator_game);
		boost::unit_test::unit_test_monitor.register_exception_translator<network::error>(&exception_translator_network);
		boost::unit_test::unit_test_monitor.register_exception_translator<config::error>(&exception_translator_config);
	}
开发者ID:AI0867,项目名称:wesnoth,代码行数:28,代码来源:main.cpp

示例9: setup_logging

/// helper method called by setup_problem
void ComputeFeatureChannelsApplication::setup_logging(std::ofstream &log_file,
                                                      const program_options::variables_map &options)
{
    if(log_file.is_open())
    {
        // the logging is already setup
        return;
    }

    // set base logging rules --
    BaseApplication::setup_logging(log_file, options);

    const bool silent_mode = get_option_value<bool>(options, "silent_mode");
    if(silent_mode == false)
    {
        // set our own stdout rules --
        logging::LogRuleSet &rules_for_stdout = logging::get_log().console_log().rule_set();
        rules_for_stdout.add_rule(logging::InfoMessage, "ComputeFeatureChannelsApplication");
#if defined(DEBUG)
        rules_for_stdout.add_rule(logging::DebugMessage, "*"); // we are debugging this application
#else
        rules_for_stdout.add_rule(logging::InfoMessage, "*"); // "production mode"
#endif
    }

    return;
}
开发者ID:Belial2010,项目名称:Pedestrian-Detection-at-100fps-Very-fast-and-accurate-pedestrian-detector12-.,代码行数:28,代码来源:ComputeFeatureChannelsApplication.cpp

示例10: LogMessage

		void LogMessage(const String& message, LogFlag flag)
		{
			time_t cm_time;
			struct tm *p_time;

			// get local time.
			time(&cm_time);
			p_time = localtime(&cm_time);

			// output to stderr.
			if (flag & log_level_)
			{
				std::cerr 
					<< '[' << std::setw(2) << std::setfill('0') << p_time->tm_hour
					<< ':' << std::setw(2) << std::setfill('0') << p_time->tm_min
					<< ':' << std::setw(2) << std::setfill('0') << p_time->tm_sec
					<< "] " << message << '\n';
			}

			// output to log file.
			if ( (flag & log_level_file_) && strm_.is_open() )
			{
				strm_
					<< '[' << std::setw(2) << std::setfill('0') << p_time->tm_hour
					<< ':' << std::setw(2) << std::setfill('0') << p_time->tm_min
					<< ':' << std::setw(2) << std::setfill('0') << p_time->tm_sec
					<< "] " << message << '\n';
			}
		}
开发者ID:donwoc,项目名称:icancode,代码行数:29,代码来源:Log.cpp

示例11: openFile

void DebugTrace::openFile( const char * filename )
{
  if( dg_debugfile.good ()&&dg_debugfile.is_open () ) dg_debugfile.close ();
  dg_debugfile.clear ();
  dg_debugfile.open( filename, std::ios::trunc&std::ios::out );
  //std::cout << filename << dg_debugfile.good () << dg_debugfile.is_open () << std::endl;
}
开发者ID:aclodic,项目名称:dynamic-graph,代码行数:7,代码来源:debug.cpp

示例12: m_dump_matches_to_stream

/*--------------------------------------------------------------------
						m_dump_matches_to_stream
----------------------------------------------------------------------*/
bool CStereoOdometryEstimator::m_dump_matches_to_stream(
				std::ofstream				& stream,
				const vector<cv::DMatch>	& matches,
				const vector<size_t>		& matches_ids )
{
	/* FORMAT
	- # of matches
		- match id
		- queryIdx
		- trainIdx
		- distance
	*/
	if( !stream.is_open() )
		return false;

	size_t num_m = matches.size(), num_m_id = matches_ids.size();
	stream.write( (char*)&num_m, sizeof(size_t) );
	stream.write( (char*)&num_m_id, sizeof(size_t) );
	const bool add_ids = num_m == num_m_id;
	for( size_t m = 0; m < matches.size(); ++m )
	{
		if( add_ids ) stream.write( (char*)&(matches_ids[m]), sizeof(size_t) );
		stream.write( (char*)&(matches[m].queryIdx), sizeof(matches[m].queryIdx) );
		stream.write( (char*)&(matches[m].trainIdx), sizeof(matches[m].trainIdx) );
		stream.write( (char*)&(matches[m].distance), sizeof(matches[m].distance) );
		stream.write( (char*)&(matches[m].imgIdx), sizeof(matches[m].imgIdx) );
	} // end-for-matches

	return true;
} // end-m_dump_matches_to_stream
开发者ID:caomw,项目名称:stereo-vo,代码行数:33,代码来源:common.cpp

示例13: checkFileIsOpen

void _LogAppenderBase::checkFileIsOpen()
{
  long int currentTime = context.now.tv_sec * 1000000 + context.now.tv_usec;

  if (nextCheckTime == 0 || currentTime >= nextCheckTime)
    {
      if (access(context.path.c_str(), F_OK) != 0)
        {
          if (out.is_open())
            {
              out.close();
            }

          try
            {
              open();
            }
          catch (...)
            {
            }
        }

      nextCheckTime = currentTime + LOG_CHECK_FILE_INTERVAL_USEC;
    }
}
开发者ID:BogdanStroe,项目名称:cubrid,代码行数:25,代码来源:cci_log.cpp

示例14: log

// Simple logging functionality: if the log file isn't already open, it tries to
// open it. If it can't, it throws a tantrum.
void log(const std::string& str) {
  if (!logFile.is_open()) {
    // Try to open the file 
    auto t = std::time(nullptr);
    auto tm = *std::localtime(&t);
    char buffer[80];
    strftime(buffer, 80, filenameFormat.c_str(), &tm);
    logFile.open(buffer,
                 std::ofstream::out);
    if (!logFile.is_open()) {
      std::cerr << "Unable to open log file.";
      exit(1);
    }
  }
  // The file is open!
  logFile << str;
}
开发者ID:bedder,项目名称:cgp-pocman,代码行数:19,代码来源:Experiment.cpp

示例15: open

 void open(const path filepath)
 {
     html_file.open(filepath.string());
     if(!html_file.is_open())
         throw std::runtime_error(
             std::string("cannot open file \"")+filepath.string()+"\" !");
     file_opened=true;
 }
开发者ID:boostan,项目名称:CISR-ODE,代码行数:8,代码来源:html.hpp


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