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


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

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


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

示例1: saveState

bool CircularNanoparticle::saveState(std::ofstream & stream)
{
	/* Format:
	*  
	*  <parent_data><mRadius><boundary>
	*/

	//call parent so it can sort out saving its part
	if(! Nanoparticle::saveState(stream) )
	{
		return false;
	}

	
	if(!stream.good())
	{
		cerr << "Error: Cannot save CircularNanoparticle. Stream not good" << endl;
		return false;
	}

	stream.write( (char*) &mRadius, sizeof(int));

	if(!stream.good())
	{
		cerr << "Error: Cannot save CircularNanoparticle. Failed writing mRadius" << endl;
		return false;
	}

	stream.write( (char*) &mBoundary, sizeof(enum boundary));

	if(!stream.good())
	{
		cerr << "Error: Cannot save CircularNanoparticle. Failed writing mBoundary" << endl;
		return false;
	}

	return true;
}
开发者ID:delcypher,项目名称:lc,代码行数:38,代码来源:circle.cpp

示例2: saveToStream

bool ProjectileRecord::saveToStream(std::ofstream& outStream) const
{
  if (!outStream.good())
  {
    DuskLog() << "ProjectileRecord::saveToStream: ERROR: stream contains errors!\n";
    return false;
  }

  uint32_t len = 0;

  //header "Proj"
  outStream.write((const char*) &cHeaderProj, sizeof(uint32_t));
  //ID
  len = ID.length();
  outStream.write((const char*) &len, sizeof(uint32_t));
  outStream.write(ID.c_str(), len);
  //Mesh
  len = Mesh.length();
  outStream.write((const char*) &len, sizeof(uint32_t));
  outStream.write(Mesh.c_str(), len);
  //TTL
  outStream.write((const char*) &DefaultTTL, sizeof(float));
  //velocity
  outStream.write((const char*) &DefaultVelocity, sizeof(float));
  //times
  outStream.write((const char*) &times, sizeof(uint8_t));
  //dice
  outStream.write((const char*) &dice, sizeof(uint8_t));
  //check
  if (!outStream.good())
  {
    DuskLog() << "ProjectileRecord::saveToStream: Error while writing data to "
              << "stream. Current projectile is \""<<ID<<"\".\n";
    return false;
  }

  return outStream.good();
}
开发者ID:Thoronador,项目名称:Dusk,代码行数:38,代码来源:ProjectileRecord.cpp

示例3: saveToStream

bool PerkRecord::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cPERK, 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);

  if (unknownVMAD.isPresent())
  {
    //write VMAD
    if (!unknownVMAD.saveToStream(output, cVMAD))
    {
      std::cout << "Error while writing subrecord VMAD of PERK!\n";
      return false;
    }
  }//if VMAD

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

  //write DESC
  if (!description.saveToStream(output, cDESC))
    return false;

  if (!subBlocks.empty())
  {
    unsigned int i;
    for (i=0; i<subBlocks.size(); ++i)
    {
      if (!subBlocks[i].subData.saveToStream(output, subBlocks[i].subType))
      {
        std::cout << "Error while writing (binary) subrecord "
                  << IntTo4Char(subBlocks[i].subType)<<" of PERK!\n";
        return false;
      }//if
    }//for
  }//if subBlocks

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

示例4: saveToStream

bool ArtObjectRecord::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cARTO, 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 OBND
  output.write((const char*) &cOBND, 4);
  //OBND's length
  subLength = 12;
  output.write((const char*) &subLength, 2);
  //write OBND
  output.write((const char*) unknownOBND, 12);

  //write MODL
  output.write((const char*) &cMODL, 4);
  //MODL's length
  subLength = modelPath.length()+1;
  output.write((const char*) &subLength, 2);
  //write model path
  output.write(modelPath.c_str(), subLength);

  if (unknownMODT.isPresent())
  {
    //write MODT
    if (!unknownMODT.saveToStream(output, cMODT))
    {
      std::cout << "Error while writing subrecord MODT of ARTO!\n";
      return false;
    }
  }//if MODT

  //write DNAM
  output.write((const char*) &cDNAM, 4);
  //DNAM's length
  subLength = 4; //fixed size
  output.write((const char*) &subLength, 2);
  //write DNAM
  output.write((const char*) &unknownDNAM, 4);

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

示例5: RotateFile

void PerfdataWriter::RotateFile(std::ofstream& output, const String& temp_path, const String& perfdata_path)
{
	ObjectLock olock(this);

	if (output.good()) {
		output.close();

		if (Utility::PathExists(temp_path)) {
			String finalFile = perfdata_path + "." + Convert::ToString((long)Utility::GetTime());
			if (rename(temp_path.CStr(), finalFile.CStr()) < 0) {
				BOOST_THROW_EXCEPTION(posix_error()
				    << boost::errinfo_api_function("rename")
				    << boost::errinfo_errno(errno)
				    << boost::errinfo_file_name(temp_path));
			}
		}
	}

	output.open(temp_path.CStr());

	if (!output.good())
		Log(LogWarning, "PerfdataWriter")
		    << "Could not open perfdata file '" << temp_path << "' for writing. Perfdata will be lost.";
}
开发者ID:LMNetworks,项目名称:icinga2,代码行数:24,代码来源:perfdatawriter.cpp

示例6: sdlog

void __cdecl sdlog(const char *fmt, ...) {
	if(ofile.good()) {
		if(!fmt) { return; }

		va_list va_alist;
		char logbuf[9999] = {0};

		va_start (va_alist, fmt);
		_vsnprintf_s(logbuf+strlen(logbuf), sizeof(logbuf) - strlen(logbuf), _TRUNCATE, fmt, va_alist);
		va_end (va_alist);

		ofile << logbuf;
		ofile.flush();
	}
}
开发者ID:Asmodean-,项目名称:dsfix,代码行数:15,代码来源:main.cpp

示例7: saveToStream

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

  if (unknownNVNM.isPresent())
  {
    //write NVNM
    if (!unknownNVNM.saveToStream(output, cNVNM))
    {
      std::cout << "Error while writing subrecord NVNM of NAVM!\n";
      return false;
    }
  }//if NVNM

  if (unknownONAM.isPresent())
  {
    //write ONAM
    if (!unknownONAM.saveToStream(output, cONAM))
    {
      std::cout << "Error while writing subrecord ONAM of NAVM!\n";
      return false;
    }
  }//if ONAM

  if (unknownNNAM.isPresent())
  {
    //write NNAM
    if (!unknownNNAM.saveToStream(output, cNNAM))
    {
      std::cout << "Error while writing subrecord NNAM of NAVM!\n";
      return false;
    }
  }//if NNAM

  if (unknownPNAM.isPresent())
  {
    //write PNAM
    if (!unknownPNAM.saveToStream(output, cPNAM))
    {
      std::cout << "Error while writing subrecord PNAM of NAVM!\n";
      return false;
    }
  }//if PNAM

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

示例8: saveToStream

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

  //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);

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

示例9: parameter

void
PeakClusterSelect::myUpdate(MarControlPtr sender)
{
  (void) sender;  //suppress warning of unused parameter(s)
  MRSDIAG("PeakClusterSelect.cpp - PeakClusterSelect:myUpdate");

  ctrl_onObservations_->setValue(1, NOUPDATE);
  ctrl_onSamples_->setValue(ctrl_inSamples_, NOUPDATE);
  ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE);
  ctrl_onObsNames_->setValue("peakLabels", NOUPDATE);

#ifdef DBG_FILE_OUT
  if (!outTextFile.good () || ! outTextFile.is_open ())
    outTextFile.open(outFileName.c_str ());
#endif
}
开发者ID:BitMax,项目名称:marsyas,代码行数:16,代码来源:PeakClusterSelect.cpp

示例10: SpeakerData

void Wiimote::SpeakerData(wm_speaker_data* sd)
{
    // TODO consider using static max size instead of new
    s16 *samples = new s16[sd->length * 2];

    if (m_reg_speaker.format == 0x40)
    {
        // 8 bit PCM
        for (int i = 0; i < sd->length; ++i)
        {
            samples[i] = (s16)(s8)sd->data[i];
        }
    }
    else if (m_reg_speaker.format == 0x00)
    {
        // 4 bit Yamaha ADPCM (same as dreamcast)
        for (int i = 0; i < sd->length; ++i)
        {
            samples[i * 2] = adpcm_yamaha_expand_nibble(m_adpcm_state, (sd->data[i] >> 4) & 0xf);
            samples[i * 2 + 1] = adpcm_yamaha_expand_nibble(m_adpcm_state, sd->data[i] & 0xf);
        }
    }

#ifdef WIIMOTE_SPEAKER_DUMP
    static int num = 0;

    if (num == 0)
    {
        File::Delete("rmtdump.wav");
        File::Delete("rmtdump.bin");
        atexit(stopdamnwav);
        OpenFStream(ofile, "rmtdump.bin", ofile.binary | ofile.out);
        wav.Start("rmtdump.wav", 6000/*Common::swap16(m_reg_speaker.sample_rate)*/);
    }
    wav.AddMonoSamples(samples, sd->length*2);
    if (ofile.good())
    {
        for (int i = 0; i < sd->length; i++)
        {
            ofile << sd->data[i];
        }
    }
    num++;
#endif

    delete[] samples;
}
开发者ID:Chiri23,项目名称:dolphin,代码行数:47,代码来源:Speaker.cpp

示例11: main

int main(int argc, char * argv[])
{
    PIN_Init(argc, argv);

    Out.open(KnobOutfile.Value().c_str());
    if (!Out.good())
    {
        std::cerr << "Unable to open '" << KnobOutfile.Value() << "'" << std::endl;
        return 1;
    }

    INS_AddInstrumentFunction(InstrumentIndirects, 0);
    PIN_AddFiniFunction(Fini, 0);

    PIN_StartProgram();
    return 0;
}
开发者ID:alugupta,项目名称:resilient-systems,代码行数:17,代码来源:context-pc.cpp

示例12: profile_init

/**
 * @brief Called once at engine initialization to set the timer
 */
void profile_init()
{
    start_profile_time = timer_get_microseconds();

    if (Cmdline_profile_write_file)
    {
        profiling_file.open("profiling.csv");

        if (!profiling_file.good())
        {
            mprintf(("Failed to open profiling output file 'profiling.csv'!"));
        }
    }

    if (Cmdline_json_profiling) {
        _mkdir("tracing");
    }
}
开发者ID:rtoijala,项目名称:fs2open.github.com,代码行数:21,代码来源:tracing.cpp

示例13: saveToStream

bool GroupData::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cGRUP, 4);
  //write size
  output.write((const char*) &m_GroupSize, 4);
  //write label
  output.write((const char*) &m_GroupLabel, 4);
  //write type
  output.write((const char*) &m_GroupType, 4);
  //write unknown data
  unsigned int i;
  for (i=0; i<2; ++i)
  {
    output.write((const char*) &(UnknownGroupDataTwo[i]), 4);
  }//for

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

示例14: OpenLog

///////////////////////////////////////////////////////////////////////
// Name: OpenLog()
// Desc: open global log file
///////////////////////////////////////////////////////////////////////
bool OpenLog ( const char* filename )
{
    String time( GetFormattedTime() );

    // open debug file
    debug_file.open ( filename, std::ios::out ); //ios::ate );
    if ( ! debug_file.good() )
      return false;

    debug_file << "<html><head><title>Savage Wheels Log File</title></head><body><h1>Savage Wheels V" << VER_MAJ << "." << VER_MIN << " - Log File</h1>";
    debug_file << "<hr/><pre>";
    debug_file <<  time << "Build: " << APP_NAME << " <br/>";
    debug_file <<  time << "Copyright &copy; 2003-2013 KenamicK Entertainment <br />";
    debug_file <<  time << "Opened on: " << __DATE__ << "<br />";
    debug_file <<  time << "Opened at: " << __TIME__ << "<br />";
    debug_file <<  time << LOG_DASH << "<br />";

    return true;
}
开发者ID:petarov,项目名称:savagewheels,代码行数:23,代码来源:Utils.cpp

示例15: logStandardOutputs

void Log::logStandardOutputs( boost::shared_ptr< sbf::pkg::Module > module )
{
	namespace bfs = boost::filesystem;
 	namespace bpx = boost::posix_time;

	// Resets previous redirection (if any)
	outRedirection.reset();
 	errRedirection.reset();
 	logRedirection.reset();

	// Creates log directory
	g_logDirectory = module->getPathSafe(sbf::pkg::VarPath) / "log";
	try 
	{
		boost::filesystem::create_directory(g_logDirectory);
	}
	catch(const std::exception& e) 
	{
		std::cerr << e.what( ) << std::endl;

	}

	// log-ulis2-0-2010-11-16_15h25m48s.txt
	g_logFilePrefix = std::string("log_") + module->getName() + module->getVersion() + "_";
	g_logFileSuffix = ".txt";

	std::stringstream ss;
	bpx::time_facet * outputFacet = new bpx::time_facet(); 
	ss.imbue( std::locale(std::locale::classic(), outputFacet) );
	// Monday-29-02-2009_14h30m12s
	outputFacet->format("%Y-%m-%d_%Hh%Mm%Ss");
	ss << g_logFilePrefix << bpx::second_clock::local_time() << g_logFileSuffix;
	g_currentLogFile = ss.str();

	static std::ofstream logFile( (g_logDirectory / g_currentLogFile ).string().c_str() );
	if(logFile.good())
	{
		outRedirection.reset(new vgDebug::StreamTee(&std::cout, &logFile));
		errRedirection.reset(new vgDebug::StreamTee(&std::cerr, &logFile));
		logRedirection.reset(new vgDebug::StreamTee(&std::clog, &logFile));
	}
}
开发者ID:npapier,项目名称:vgsdk,代码行数:42,代码来源:helpers.cpp


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