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


C++ std::ofstream类代码示例

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


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

示例1: outputGlobalPropFile

void VisualStudioProvider::outputGlobalPropFile(std::ofstream &properties, int bits, const StringList &defines, const std::string &prefix, bool runBuildEvents) {
	std::string warnings;
	for (StringList::const_iterator i = _globalWarnings.begin(); i != _globalWarnings.end(); ++i)
		warnings +=  *i + ';';

	std::string definesList;
	for (StringList::const_iterator i = defines.begin(); i != defines.end(); ++i) {
		if (i != defines.begin())
			definesList += ';';
		definesList += *i;
	}

	// Add define to include revision header
	if (runBuildEvents)
		definesList += REVISION_DEFINE ";";

	properties << "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>\n"
	              "<VisualStudioPropertySheet\n"
	              "\tProjectType=\"Visual C++\"\n"
	              "\tVersion=\"8.00\"\n"
	              "\tName=\"" << PROJECT_DESCRIPTION << "_Global\"\n"
	              "\tOutputDirectory=\"$(ConfigurationName)" << bits << "\"\n"
	              "\tIntermediateDirectory=\"$(ConfigurationName)" << bits << "/$(ProjectName)\"\n"
	              "\t>\n"
	              "\t<Tool\n"
	              "\t\tName=\"VCCLCompilerTool\"\n"
	              "\t\tDisableLanguageExtensions=\"true\"\n"
	              "\t\tDisableSpecificWarnings=\"" << warnings << "\"\n"
	              "\t\tAdditionalIncludeDirectories=\"" << prefix << ";" << prefix << "\\engines;$(" << LIBS_DEFINE << ")\\include;$(TargetDir)\"\n"
	              "\t\tPreprocessorDefinitions=\"" << definesList << "\"\n"
	              "\t\tExceptionHandling=\"0\"\n";

#if NEEDS_RTTI
	properties << "\t\tRuntimeTypeInfo=\"true\"\n";
#else
	properties << "\t\tRuntimeTypeInfo=\"false\"\n";
#endif

	properties << "\t\tRuntimeTypeInfo=\"false\"\n"
	              "\t\tWarningLevel=\"4\"\n"
	              "\t\tWarnAsError=\"false\"\n"
	              "\t\tCompileAs=\"0\"\n"
	              "\t\t/>\n"
	              "\t<Tool\n"
	              "\t\tName=\"VCLibrarianTool\"\n"
	              "\t\tIgnoreDefaultLibraryNames=\"\"\n"
	              "\t/>\n"
	              "\t<Tool\n"
	              "\t\tName=\"VCLinkerTool\"\n"
	              "\t\tIgnoreDefaultLibraryNames=\"\"\n"
	              "\t\tSubSystem=\"1\"\n"
	              "\t\tEntryPointSymbol=\"WinMainCRTStartup\"\n"
	              "\t\tAdditionalLibraryDirectories=\"$(" << LIBS_DEFINE << ")\\lib\\" << ((bits == 32) ? "x86" : "x64") << "\"\n"
	              "\t/>\n"
	              "\t<Tool\n"
	              "\t\tName=\"VCResourceCompilerTool\"\n"
	              "\t\tPreprocessorDefinitions=\"HAS_INCLUDE_SET\"\n"
	              "\t\tAdditionalIncludeDirectories=\"" << prefix << "\"\n"
	              "\t/>\n"
	              "</VisualStudioPropertySheet>\n";

	properties.flush();
}
开发者ID:bluddy,项目名称:scummvm,代码行数:63,代码来源:visualstudio.cpp

示例2: setup

namespace Log {

   // component-scope variables
   const unsigned int log_master = 0;
   std::string log_file;
   std::ofstream lout;

   bool initialized = false;
   std::stringstream buffer;

   // =========================================================================
   // Set up

   void setup () {

      // ----------------------------------------------------------------------
      // Initialize the Log component

      // Name of log file
      log_file = Parameters::get_optional<std::string>(
            "Log.log_file", "log.txt");
      log_file = Driver::output_dir + log_file;

      // Open log file
#ifdef PARALLEL_MPI
      if (Driver::proc_ID == log_master) {
         lout.open(log_file.c_str());
      }
#else // PARALLEL_MPI
      lout.open(log_file.c_str());
#endif // PARALLEL_MPI
      initialized = true;

      // Write the log file header
      lout << "Hydrodynamics Simulation" << std::endl << std::endl;

      // If the buffer is not empty, push it to the file
      lout << buffer.str();
      buffer.clear();
      buffer.str("");

   }

   // =========================================================================
   // Clean up

   void cleanup () {

      // Final printing
      write_single("\n" + std::string(79,'_') + "\nProgram Complete\n");

      if (initialized) {
         // If the log file is open, close it
#ifdef PARALLEL_MPI
         if (Driver::proc_ID == log_master) {
#endif // PARALLEL_MPI
            lout.close();
            initialized = false;
#ifdef PARALLEL_MPI
         }
#endif // PARALLEL_MPI
      } else {
         // If the log file was never opened, print the buffer to the screen
         std::cout << buffer.str();
         buffer.clear();
         buffer.str("");
      }

   }

   // =========================================================================
   // Write to the log file

   void write_all(std::string message) {
#ifdef PARALLEL_MPI
      // Declare variables
      int length, max_length;
      char *send_buf, *recv_buf;

      // MPI_Allreduce to determine length of longest message
      length = message.length();
      MPI_Allreduce(&length, &max_length, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);

      // Pad message to max_length
      message.resize(max_length, '\0');

      // Allocate a character array of max_length
      send_buf = (char*) message.c_str();
      recv_buf = new char[Driver::n_procs*max_length];

      // MPI_Gather the messages into a read buffer
      MPI_Gather(send_buf, max_length, MPI_CHAR,
                 recv_buf, max_length, MPI_CHAR, log_master, MPI_COMM_WORLD);

      // If you are the master:
      if (Driver::proc_ID == log_master) {
         // Parse the read buffer into individual messages
         for (int i = 0; i < Driver::n_procs; i++) {
            for (int j = 0; j < max_length; j++) {
               if (recv_buf[i*max_length+j] == '\0') {
//.........这里部分代码省略.........
开发者ID:bkkrueger,项目名称:toy_hydro,代码行数:101,代码来源:Log.cpp

示例3: saveToStream

bool EyeRecord::saveToStream(std::ofstream& output) const
{
    output.write((const char*) &cEYES, 4);
    if (!saveSizeAndUnknownValues(output, getWriteSize())) return false;

    //write EDID
    output.write((const char*) &cEDID, 4);
    //EDID's length
    uint16_t subLength = editorID.length()+1;
    output.write((const char*) &subLength, 2);
    //write editor ID
    output.write(editorID.c_str(), subLength);

    //write FULL
    if (!name.saveToStream(output, cFULL))
        return false;

    //write ICON
    output.write((const char*) &cICON, 4);
    //ICON's length
    subLength = iconPath.length()+1;
    output.write((const char*) &subLength, 2);
    //write icon path
    output.write(iconPath.c_str(), subLength);

    //write DATA
    output.write((const char*) &cDATA, 4);
    //DATA's length
    subLength = 1;
    output.write((const char*) &subLength, 2);
    //write DATA's content
    output.write((const char*) &flags, 1);

    return output.good();
}
开发者ID:Thoronador,项目名称:morrowtools,代码行数:35,代码来源:EyeRecord.cpp

示例4: saveParameters

bool Cylinder::saveParameters(std::ofstream& fout) const
{
  fout << "# cylinder normal_x normal_y normal_z point_x point_y point_z radius" << std::endl;
  fout << "cylinder " << _normal << " " << _point << " " << _radius << std::endl;
  return fout.good();
}
开发者ID:caomw,项目名称:GlobFit,代码行数:6,代码来源:Cylinder.cpp

示例5: saveToStream

bool PathGridRecord::saveToStream(std::ofstream& output) const
{
    output.write((const char*) &cPGRD, 4);
    uint32_t Size;
    Size = 4 /* DATA */ +4 /* 4 bytes for length */ + 12 /* size of data */
           +4 /* NAME */ +4 /* 4 bytes for length */
           +CellName.length()+1 /* length of cell name +1 byte for NUL termination */;
    if (!Points.empty())
    {
        Size = Size + 4 /* PGRP */ +4 /* 4 bytes for length */
               +16 * Points.size();
    }
    if (!Connections.empty())
    {
        Size = Size + 4 /* PGRC */ +4 /* 4 bytes for length */
               +8 * Connections.size();
    }
    output.write((const char*) &Size, 4);
    output.write((const char*) &HeaderOne, 4);
    output.write((const char*) &HeaderFlags, 4);

    /*Path Grid:
      DATA = (path grid data, 12 bytes)
               int32_t GridX
               int32_t GridY
               uint16_t Granularity (a power of two within [128;4096])
               uint16_t NumQuads (number of points in PGRP)
      NAME = name of cell the grid belongs to
      PGRP = unknown data (path grid points?)
               looks like an array of int32_t quads
               struct PointData
               {
                 int32_t X
                 int32_t Y
                 int32_t Z
                 int32_t Unknown
               };

      PGRC = unknown data (length: ?)
               Possibly path grid connections?
               Looks like an array of uint32_t pairs, where
               first value is the index of the starting point
               and second value is index of the end point.
    */

    //write DATA
    output.write((const char*) &cDATA, 4);
    //DATA's length
    uint32_t SubLength;
    SubLength = 12; //length is always twelve bytes
    output.write((const char*) &SubLength, 4);
    //write path grid data
    output.write((const char*) &GridX, 4);
    output.write((const char*) &GridY, 4);
    output.write((const char*) &Granularity, 2);
    output.write((const char*) &NumQuads, 2);

    //write NAME
    output.write((const char*) &cNAME, 4);
    //NAME's length
    SubLength = CellName.length()+1;//length of string plus one for NUL-termination
    output.write((const char*) &SubLength, 4);
    //write cell name
    output.write(CellName.c_str(), SubLength);

    if (!Points.empty())
    {
        //write PGRP
        output.write((const char*) &cPGRP, 4);
        //PGRP's length
        SubLength = Points.size()*16;//length is 16 bytes per point
        output.write((const char*) &SubLength, 4);
        //write points
        unsigned int i;
        for (i=0; i<Points.size(); ++i)
        {
            //write next point
            output.write((const char*) &(Points[i].X), 4);
            output.write((const char*) &(Points[i].Y), 4);
            output.write((const char*) &(Points[i].Z), 4);
            output.write((const char*) &(Points[i].Unknown), 4);
        }//for
    }//Points

    if (!Connections.empty())
    {
        //write PGRC
        output.write((const char*) &cPGRC, 4);
        //PGRC's length
        SubLength = Connections.size()*8;//length is 8 bytes per connection
        output.write((const char*) &SubLength, 4);
        //write connections
        unsigned int i;
        for (i=0; i<Connections.size(); ++i)
        {
            //write next point
            output.write((const char*) &(Connections[i].Start), 4);
            output.write((const char*) &(Connections[i].End), 4);
        }//for
    }//connections
//.........这里部分代码省略.........
开发者ID:Thoronador,项目名称:morrowtools,代码行数:101,代码来源:PathGridRecord.cpp

示例6: createOutputFile

void createOutputFile (std::ofstream & outputFile, FILE * ptr_fp, bool isRestart, double delT, double delV, 
		       double tMin, double tMax, double vMin, double vMax, int Nvsteps, int Ntsteps, 
		       int downSampleT, int downSampleV, char * rChoice, char * regionChoice, 
		       char * distChoice, char * scattType, char * gradientOption, double vthe, 
		       double memi, double B, double wpe, double wce, double wci, double beta_e, 
		       double vA, double c1, double nu, double omega, double delB, double deln, 
		       double delR, double kpar, int Lx, int l0) {
  
  if (isRestart == 1) {
    outputFile.open("outputFile.txt", std::ios::out | std::ios::app); 
    std::cout << "Restart -> appending already existing outfile" << std::endl; 
  } else {

    // Opening output file 
    outputFile.open("outputFile.txt"); 

    // Opening saving file
    /*if((ptr_fp = fopen("cppTestOutput.bin", "ab")) == NULL)
      {
	printf("Unable to open file!\n");
	exit(1);
	}else printf("Opened file successfully for writing.\n");*/
    
    // Adding important information to the output file
    outputFile << "Simulation Variables:" << std::endl; 
    outputFile << "delT = " << delT << std::endl; 
    outputFile << "delV = " << delV << std::endl;
    outputFile << "tMin = " << tMin << std::endl; 
    outputFile << "tMax = " << tMax << std::endl; 
    outputFile << "vMin = " << vMin << std::endl; 
    outputFile << "vMax = " << vMax << std::endl;
    outputFile << "Nvsteps = " << Nvsteps << std::endl;
    outputFile << "Ntsteps = " << Ntsteps << std::endl; 
    outputFile << "downSampleT = " << downSampleT << std::endl; 
    outputFile << "downSampleV = " << downSampleV << std::endl << std::endl; 
  
    outputFile << "Physical Variables:" << std::endl;
    outputFile << "rChoice = " << rChoice << std::endl; 
    outputFile << "regionChoice = " << regionChoice << std::endl; 
    outputFile << "distChoice = " << distChoice << std::endl; 
    outputFile << "scattType = " << scattType << std::endl; 
    outputFile << "gradientOption = " << gradientOption << std::endl << std::endl;

    outputFile << "Physical Parameters:" << std::endl; 
    outputFile << "vthe = " << vthe << std::endl; 
    outputFile << "memi = " << memi << std::endl; 
    outputFile << "B = " << B << std::endl;
    outputFile << "wpe = " << wpe << std::endl;
    outputFile << "wce = " << wce << std::endl;
    outputFile << "wci = " << wci << std::endl;
    outputFile << "beta_e = " << beta_e << std::endl;
    outputFile << "vA = " << vA << std::endl;
    outputFile << "c1 = " << c1 << std::endl;
    outputFile << "nu = " << nu << std::endl;
    outputFile << "omega = " << omega << std::endl;
    outputFile << "delB = " << delB << std::endl;
    outputFile << "deln = " << deln << std::endl;
    outputFile << "delR = " << delR << std::endl;
    outputFile << "kpar = " << kpar << std::endl;
    outputFile << "Lx = " << Lx << std::endl;
    outputFile << "l0 = " << l0 << std::endl << std::endl;

    outputFile << "Simulation Output:" << std::endl;
  }
}
开发者ID:elichko27,项目名称:MagneticPumping,代码行数:65,代码来源:createOutputFile.cpp

示例7: closeFileStream

 static void closeFileStream(std::ofstream& fileStream) {
     assert_true(fileStream.good());
     fileStream.close();
 }
开发者ID:AlexanderKazakov,项目名称:gcm,代码行数:4,代码来源:FileUtils.hpp

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

示例9: trace_instrument

VOID trace_instrument(TRACE trace, VOID *v){
  for (BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl = BBL_Next(bbl)){ 
    /* iterate over all basic blocks */
    
    string codelet_string = "";
    // this writes disassembly 
    char codelet_buffer[65536*2]; int cbs = 0;
    INS head = BBL_InsHead(bbl);
    INS tail = BBL_InsTail(bbl);
    
    ADDRINT stage_entry = INS_Address( head );
    ADDRINT target = 0;
    if (INS_IsCall(tail)){
      if( INS_IsDirectBranchOrCall(tail)){
        target = INS_DirectBranchOrCallTargetAddress(tail);}}

    INS cur ;
    int branch_id = slp_count;
      
    /* If compression is turned off (default), only output the addresses of
     * the BBL once
     */
    if (!KnobNoCompress){
      /* Instrument the head instruction right before it is called, but also
       * before we instrument the instructions in the basic block 
       */
      string msg_pre  = "\[email protected]@BBL(" + decstr( branch_id ) + ") STAGE " + Target2String(stage_entry)->c_str() + "\n" ;
      INS_InsertCall(head, IPOINT_BEFORE, AFUNPTR(string_report),
		     IARG_PTR, new string(msg_pre),
		     IARG_END);
    }
   
    /* Walk the list of instructions inside the BBL. Disassemble each, and add
     * it to the codelet string. Also, instrument each instruction at the
     * point before it is called with the do_count function.
     */
    for ( cur = head; INS_Valid( cur ); cur = INS_Next(cur ) ){
      cbs += sprintf( codelet_buffer + cbs , "\n\[email protected]%llx\t%s", INS_Address( cur ), INS_Disassemble( cur ).c_str() );
      INS_InsertCall(cur, IPOINT_BEFORE, (AFUNPTR)do_count, IARG_ADDRINT, INS_Address( cur ), IARG_END);
    }

    /* Finish off the codelet assembly string with an out message and
     * address ranges of the BBL
     */
    cbs += sprintf( codelet_buffer + cbs , "\n\t}BBL.OUT [%d] %llx - %llx\n", branch_id, INS_Address( head ), INS_Address( tail ));
  
    /* If compression is turned on, output the codelet every single time we
     * hit the same block.
     */
    if(KnobNoCompress){
      INS_InsertCall(tail, IPOINT_BEFORE, AFUNPTR(string_report),
		     IARG_PTR, new string(codelet_buffer),
		     IARG_END);
      slp_count ++;
    }
    else{
      /* add the mapped BBL to output */
      TraceFile.write(codelet_buffer, cbs);	
 
      /* Instrument the tail instruction by inserting just before it is called
      */
      string msg_post = "[email protected]@BBL(" + decstr( branch_id ) + ") ACHIEVE : GOTO " + Target2String(target)->c_str();
      INS_InsertCall(tail, IPOINT_BEFORE, AFUNPTR(string_report),
		     IARG_PTR, new string(msg_post),
		     IARG_END);

      slp_count ++;
    }
  }
}
开发者ID:toejamhoney,项目名称:pin,代码行数:70,代码来源:map_syms.cpp

示例10: Fini

VOID Fini(INT32 code, VOID *v)
{
    TraceFile.close();
}
开发者ID:toejamhoney,项目名称:pin,代码行数:4,代码来源:map_syms.cpp

示例11: write

		bool write(const uint8_t v) { m_fp.put(v); return true; }
开发者ID:DimitrisVlachos,项目名称:lib_bitstreams,代码行数:1,代码来源:file_stream.hpp

示例12:

AutoThread::~AutoThread()

{
    output.close();

}
开发者ID:andrea-nisti,项目名称:mavutils,代码行数:6,代码来源:AutoThread.cpp

示例13: tell

		uint64_t tell() { return m_fp.tellp(); }
开发者ID:DimitrisVlachos,项目名称:lib_bitstreams,代码行数:1,代码来源:file_stream.hpp

示例14: is_open

		bool is_open() { return m_fp.is_open(); }
开发者ID:DimitrisVlachos,项目名称:lib_bitstreams,代码行数:1,代码来源:file_stream.hpp

示例15: flush

 void flush() {
    lout.flush();
 }
开发者ID:bkkrueger,项目名称:toy_hydro,代码行数:3,代码来源:Log.cpp


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