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


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

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


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

示例1: initLogger

void initLogger(int networkId)
{
	// Error file
	if (gErrorFile.is_open())
	{
		gErrorFile.close();
		gErrorFile.clear();
	}

	std::stringstream errorFile;
	errorFile << "../error_log_" << networkId << ".txt";
	gErrorFilePath = errorFile.str();
	gErrorFile.open(gErrorFilePath.c_str());

	// Debug message file
	if (gDebugMessageFile.is_open())
	{
		gDebugMessageFile.close();
		gDebugMessageFile.clear();
	}

	std::stringstream debugFile;
	debugFile << "../debug_message_log_" << networkId << ".txt";
	gDebugMessageFilePath = debugFile.str();
	gDebugMessageFile.open(gDebugMessageFilePath.c_str());
}
开发者ID:GustavPersson,项目名称:dansbandet,代码行数:26,代码来源:Macros.cpp

示例2: writeTrajectory

void writeTrajectory(TrajectoryBasePtr ptraj){

	mtx_.lock();
	stringstream ss;
	if (!!(ptraj)){
	
		if ((ptraj->GetDuration() < timer)){
			timer = ptraj->GetDuration();
			//std::cout << "Storing Trajectory with following info" << std::endl;
			//std::cout << timer << std::endl;
			ptraj->serialize(ss);
			traj.open("traj.xml");
			traj.clear();
			traj << ss.str();
			traj.close();
		}
		else {
			//std::cout << "Ignoring Trajectory Files" << std::endl;
		}

	}
	else {
		//std::cout << "Planning Failed : trajectory empty" << std::endl;
	}
	mtx_.unlock();

}
开发者ID:praman2s,项目名称:multithreadedbaseplacement-openrave,代码行数:27,代码来源:baseplacement_threaded_ln.cpp

示例3: if

  std::ostream& LoggerImpl::getAppender()
  {
    if (pipe)
      return *pipe;
    else if (!fname.empty())
    {
      if (!outfile.is_open())
      {
        outfile.clear();
        outfile.open(fname.c_str(), std::ios::out | std::ios::app);
        counter.resetCount(outfile.tellp());
      }

      if (maxfilesize > 0)
      {
        if (counter.getCount() > maxfilesize)
        {
          doRotate();
          counter.resetCount();
        }
        return tee;
      }
      else
        return outfile;
    }
    else if (loghost.isConnected())
      return udpmessage;
    else
      return std::cerr;
  }
开发者ID:gema-arta,项目名称:zim-vendor,代码行数:30,代码来源:log.cpp

示例4: openFile

 void sotDebugTrace::openFile( const char * filename )
 {
   if( debugfile.good()&&debugfile.is_open() ) debugfile.close();
   debugfile.clear();
   debugfile.open( filename, std::ios::trunc&std::ios::out );
   //std::cout << filename << debugfile.good() << debugfile.is_open() << std::endl;
 }
开发者ID:RIVeR-Lab,项目名称:ihmc-open-robotics-software,代码行数:7,代码来源:debug.cpp

示例5: open

		void open(bool truncate)
		{
			if (open_filename == m_filename) return;
			log_file.close();
			log_file.clear();
			log_file.open(m_filename.c_str(), truncate ? std::ios_base::trunc : std::ios_base::app);
			open_filename = m_filename;
			if (!log_file.good())
				fprintf(stderr, "Failed to open logfile %s: %s\n", m_filename.c_str(), strerror(errno));
		}
开发者ID:kuro,项目名称:libtorrent,代码行数:10,代码来源:debug.hpp

示例6: promptUserForFile

std::string promptUserForFile(std::ofstream &outFile, std::string prompt) {
    while (true) {
        std::cout << prompt;
        std::string fileName;
        getline(std::cin, fileName);
        outFile.open(fileName.c_str());
        if (!outFile.fail()) return fileName;
        outFile.clear();
        std::cout << "Unable to open that file. Try again." << std::endl;
        if (prompt == "") prompt = "Output file: ";
        
    }
}
开发者ID:NikkiJain09,项目名称:programming-abstractions,代码行数:13,代码来源:4_09.cpp

示例7: defined

bool FileSystem::rawopen
	(
	std::ofstream& out,			// Output stream to open.
	const string &fname,			// May be converted to upper-case.
	bool is_text				// Should the file be opened in text mode
	)
{
	string name = fname;
	if (!rewrite_virtual_path(name)) {
		con.Print_err(MM_MAJOR_WARN, "Illegal file access\n");
		return false;
	}

#if defined(MACOS) || (__GNUG__ > 2)
	std::ios_base::openmode mode = std::ios::out | std::ios::trunc;
	if (!is_text) mode |= std::ios::binary;
#elif defined(UNIX)
	int mode = std::ios::out | std::ios::trunc;
#else
	int mode = std::ios::out | std::ios::trunc;
	if (!is_text) mode |= std::ios::binary;
#endif
	switch_slashes(name);

	// We first "clear" the stream object. This is done to prevent
	// problems when re-using stream objects
	out.clear();

	int uppercasecount = 0;
	do {
		out.open(name.c_str(), mode);		// Try to open
		if (out.good()) return true;		// found it!
		out.clear();						// Forget ye not
	} while (base_to_uppercase(name, ++uppercasecount));

	// file not found.
	return false;
}
开发者ID:amichaelt,项目名称:pentagram,代码行数:38,代码来源:FileSystem.cpp

示例8: reset

 virtual void reset() {
   DVLOG(5) << "resetting histogram";
   if (!log_initialized) {
     log_initialized = true;
     char * jobid = getenv("SLURM_JOB_ID");
     char fname[256]; sprintf(fname, "histogram.%s/%s.%d.out", jobid, name, mycore());
     log.open(fname, std::ios::out | std::ios_base::binary);
     DVLOG(5) << "opened " << fname;
   }
   if (log_initialized) {
     log.clear();
     log.seekp(0, std::ios::beg);
   }
   value_ = nil_value;
 }
开发者ID:HPCProjectsTry,项目名称:grappa,代码行数:15,代码来源:HistogramMetric.hpp

示例9: parse_template

void parse_template(template_files_vector::iterator i, std::ifstream &input, std::ofstream &output, const symbol_map &symbols)
{
    std::string line;
    parser_vector parsers;
    parsers.push_back(parser_object_ptr(new symbol_parser(symbols, parsers, input, output)));

    input.open(i->first.c_str(), std::ios::in);
    string_pair &out_file = i->second;
    output.open(std::string(out_file.first + symbols.find("NAME_LOWER")->second + out_file.second).c_str(),
        std::ios::out | std::ios::trunc);

    if( !input.is_open() )
        throw std::runtime_error("Failed to open template file");
    if( !output.is_open() )
        throw std::runtime_error("Failed to open output file");

    std::string buff;

    // read and write line by line
    while(true)
    {
        symbol_parser::m_should_output = true;

        std::getline(input, line);
        buff = line;

        if( input.eof() )
            break;

        if( !input.good() || !output.good() )
            throw std::runtime_error("Input or Output error!");

        for( parser_vector::reverse_iterator i = parsers.rbegin(), end = parsers.rend(); i != end; ++i )
            if( (**i)(buff) )
                break;
    }

    input.close();
    output.close();
    input.clear();
    output.clear();
}
开发者ID:BackupTheBerlios,项目名称:cpaf-svn,代码行数:42,代码来源:main.cpp

示例10: openOutputFile

//--- Open an output file.
//
//   Note not under unit test.
//
bool openOutputFile(std::ofstream& fileStream, const char *const fileName, std::ios_base::openmode mode,
  std::string& errStr)
  {
  //
  // Start with a clean slate.
  if( fileStream.is_open() )
    fileStream.close();
  fileStream.clear(std::ios_base::goodbit);
  //
  // Open file.
  fileStream.open(fileName, mode);
  if( fileStream.fail() )
    {
    if( 0 != errStr.size() )
      errStr.push_back('\n');
    errStr.append("Failed to open file '").append(fileName).push_back('\'');
    return( 0 );
    }
  //
  return( 1 );
  }  // End fcn openOutputFile().
开发者ID:Pampipampupampa,项目名称:Cours-Python,代码行数:25,代码来源:file-help.cpp

示例11: doRotate

  void LoggerImpl::doRotate()
  {
    outfile.clear();
    outfile.close();

    // ignore unlink- and rename-errors. In case of failure the
    // original file is reopened

    std::string newfilename = mkfilename(maxbackupindex);
    ::unlink(newfilename.c_str());
    for (unsigned idx = maxbackupindex; idx > 0; --idx)
    {
      std::string oldfilename = mkfilename(idx - 1);
      ::rename(oldfilename.c_str(), newfilename.c_str());
      newfilename = oldfilename;
    }

    ::rename(fname.c_str(), newfilename.c_str());

    outfile.open(fname.c_str(), std::ios::out | std::ios::app);
    counter.resetCount(outfile.tellp());
  }
开发者ID:gema-arta,项目名称:zim-vendor,代码行数:22,代码来源:log.cpp

示例12: promptUserForFile

std::string promptUserForFile(std::ofstream& stream,
                              const std::string& prompt,
                              const std::string& reprompt) {
    std::string promptCopy = prompt;
    std::string repromptCopy = reprompt;
    if (reprompt == "") {
        repromptCopy = "Unable to open that file.  Try again.";
    }
    appendSpace(promptCopy);
    while (true) {
        std::cout << promptCopy;
        std::string filename;
        getline(std::cin, filename);
        if (!filename.empty()) {
            openFile(stream, filename);
            if (!stream.fail()) return filename;
            stream.clear();
        }
        std::cout << repromptCopy << std::endl;
        if (promptCopy == "") promptCopy = "Output file: ";
    }
}
开发者ID:mahmoudmheisen91,项目名称:Programing_Abstractions,代码行数:22,代码来源:filelib.cpp

示例13: generate_ham_cycle

// visit generate_ham_cycles_helper
void generate_ham_cycle(int m, int n, int v)
{
	int size = m * n;
	int column = n;
        int** matrix;
        generate_grid_matrix(matrix, m, n);
        ///////////////////////////////////////////////////////
	fout.open("cuda/matrix.in");
	fout << "  " << size << std::endl;
        for(int i = 0; i < size; ++i){
                for(int j = 0; j < size; ++j){
                        fout << std::setw(3) << matrix[i][j];
                }
                fout << std::endl;
        }
	fout.close();
	fout.clear();
        ///////////////////////////////////////////////////////
	//print adjacency matrix for grid graph
        //for(int i = 0; i < size; ++i){
        //        for(int j = 0; j < size; ++j){
        //                std::cout << matrix[i][j] << ' ';
        //                //std::cout << matrix[i][j] << ", ";
        //        }
        //        std::cout << std::endl;
        //}
        ///////////////////////////////////////////////////////
        bool* visit; // = {0,};
	visit = new bool[size];
        for(int i = 0; i < size; ++i){
                visit[i] = false;
        }

        int w = v - 1;		    // starting node of hamiltonian cycle
        std::vector<int> myvector;
        myvector.push_back(w);      // start of hamiltonian cycle
        std::cout << std::endl;
        generate_ham_cycle_helper(w, w, myvector, matrix, visit, size, column);
        std::cout << " Count of HAMILTONIAN CYCLES  " << cycles.size() << std::endl << std::endl;
        //std::cout << "\nCount of HAMILTONIAN CYCLES = " 
        //          << generate_ham_cycle_helper(w, w, myvector, matrix, visit, size, column) 
        //          << std::endl << std::endl;
	//print all hamiltonian cycles
	//for(int i = 0; i < cycles.size(); ++i){
	//	print_vector(cycles[i]);
	//}
	int s = cycles.size();
	if(s) {
		int t,c1,c2;
		int min = distance(0, 0);
		long unsigned int sum1 = 0;
		long unsigned int sum2 = 0;
		std::vector<int> f1;
		std::vector<int> f2;
		c1 = 0;
		c2 = 0;
		//variables for non simetrical cycles
		bool b = true;
		unsigned int count = 0;
		fout.open("octave/functions.in");
		for(int i = 0; i < s; ++i){
			//sum and f1 functions of C1 cycle
			sum1 = charac_function(cycles[i], f1, column);
			for(int j = i + 1; j < s; ++j){
				//sum and f2 functions of C2 cycle
				sum2 = charac_function(cycles[j], f2, column);
				if(if_equal(f1, f2)){
					b = false;
				// print cycles, which function are equaly
				//	print_function(f1);
				//	print_vector_in_grid(cycles[i], column);
				//	print_vector_in_grid(cycles[j], column);
				}
				t = distance(i,j);
				if(min > t){
					min = t;
					c1 = i;
					c2 = j;
				}
			}
			if(b) {
			//print non charac. functions to file functions.in
				print_function_to_file(f1);
				++count;
			}
			b = true;
		}
		fout.close();
		fout.clear();
		std::cout << " Count of non simetrical HAMILTONIAN CYCLES  " 
                          << count << std::endl << std::endl;
		std::cout << " nm   " << size << std::endl;
		std::cout << " min distance   " << min << std::endl;
		std::cout << " max distance   " << 2 * size - 2 * min << std::endl;
		//print_vector(cycles[c1]);
		//print_vector(cycles[c2]);
		print_vector_in_grid(cycles[c1], column);
		print_vector_in_grid(cycles[c2], column);
		//for(int i = 0; i < s; ++i){
//.........这里部分代码省略.........
开发者ID:gurgen2727,项目名称:square_grids,代码行数:101,代码来源:functions.cpp

示例14: openTextFileStream

 /** Open file stream to write in */
 static void openTextFileStream(std::ofstream& fileStream,
                                const std::string& fileName) {
     fileStream.open(fileName, std::ios::out);
     assert_true(fileStream.is_open());
     fileStream.clear();
 }
开发者ID:AlexanderKazakov,项目名称:gcm,代码行数:7,代码来源:FileUtils.hpp

示例15: seekwriting

 void seekwriting(unsigned long int& seekpos) {
     ofs_.clear();
     ofs_.seekp(B_HEADERSIZE+seekpos);
 }
开发者ID:priyankatanvani,项目名称:fire-cbir,代码行数:4,代码来源:largebinaryfeaturefile.hpp


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