本文整理汇总了C++中std::ofstream::open方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::open方法的具体用法?C++ ofstream::open怎么用?C++ ofstream::open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ofstream
的用法示例。
在下文中一共展示了ofstream::open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeData
void Profiler::writeData() const
{
outStream.open(fileName, std::ios::trunc);
// Write category headers
for (uint i = 0; i < numUsedCategories; i++)
{
outStream << categories[i].name;
outStream << getDelimiter(i);
}
uint endIndex;
uint startIndex;
if (wrapped())
{
endIndex = frameIndex % MAX_FRAME_SAMPLES;
startIndex = (endIndex + 1) % MAX_FRAME_SAMPLES;
while (startIndex != endIndex)
{
writeFrame(startIndex);
startIndex = (startIndex + 1) % MAX_FRAME_SAMPLES;
}
if (currentFrameComplete())
writeFrame(startIndex);
}
else
{
uint numActualFrames = frameIndex;
if (currentFrameComplete())
numActualFrames++;
startIndex = 0;
endIndex = numActualFrames;
while (startIndex < endIndex)
writeFrame(startIndex++);
}
outStream.close();
}
示例2: 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;
}
示例3: OpenFile
void OpenFile()
{
//std::cout << "LogManager try to open file to " << sLogFileName << std::endl;
if (logFile.is_open())
{
logFile << "Change to log file: "<< sLogFileName<< std::endl;
TimeTag();
EndFile();
logFile.close();
}
//First attempt to create the log file.
std::ostringstream filename;
filename << "results/logs/" << theApp->getStartTimeString() << "-eventLog";
if (mSide == RED) {
filename << "Red";
} else if (mSide == BLUE) {
filename << "Blue";
}
filename << ".txt";
logFile.open(filename.str().c_str());
//logFile.open(sLogFileName);
if (!logFile.is_open())
{
std::cout << "could not open file \""<<filename.str()<<"\"" << std::endl;
return;
}
else
{
//std::cout << "Using file \"delta3d_log.html\" for logging" << std::endl;
}
//TimeTag();
//logFile << std::endl;
logFile.flush();
//std::cout.flush();
}
示例4: main
int main(int argc, char *argv[])
{
// Initialize pin & symbol manager
PIN_InitSymbols();
if( PIN_Init(argc,argv) )
{
return Usage();
}
// Write to a file since cout and cerr maybe closed by the application
TraceFile.open(KnobOutputFile.Value().c_str());
TraceFile << hex;
TraceFile.setf(ios::showbase);
// Register Image to be called to instrument functions.
IMG_AddInstrumentFunction(Image, 0);
PIN_AddFiniFunction(Fini, 0);
// Never returns
PIN_StartProgram();
return 0;
}
示例5: main
/* =====================================================================
* Entry point for the tool
* ===================================================================== */
int main(int argc, char * argv[])
{
if (PIN_Init(argc, argv))
{
return Usage();
}
PIN_InitSymbols();
PIN_SemaphoreInit(&SemAllThreadStarted);
PIN_MutexInit(&MtxVecThreadIds);
PIN_MutexInit(&MtxActiveThread);
Out.open(KnobOutputFile.Value().c_str());
ASSERT(Out, "Failed to open file " + KnobOutputFile.Value());
IMG_AddInstrumentFunction(Image, 0);
PIN_AddFiniFunction(OnExit, 0);
// Never returns
PIN_StartProgram();
return 0;
}
示例6: main
int main(int argc, char *argv[])
{
if (PIN_Init(argc, argv))
return usage();
outfile.open("arqsimucache.out");
INS_AddInstrumentFunction(instrument_instruction, 0);
PIN_AddFiniFunction(finalize, 0);
RAM *ram = new RAM();
Cache *l2 = new Cache("L2", ram, 1000*1024, 2, 16);
Cache *l1 = new Cache("L1", l2, 64*1024, 2, 16);
front_memory = l1;
// start program and never return
PIN_StartProgram();
return 0;
}
示例7: open_store
void open_store(std::string outfile) {
owl_file.open(outfile.c_str(), std::ios::out);
// Write Prefix
if (owl_file.is_open()) {
for (std::map<std::string, std::string>::iterator it =
prefixes.begin(), ie = prefixes.end(); it != ie; ++it) {
owl_file << "Prefix(" << it->first << "=" << ANGLEQUOTE(it->second)
<< ")\n";
}
owl_file << "\n";
// Write Ontology
owl_file << "Ontology(" << ANGLEQUOTE(ontologyName) << "\n";
// Write Import
if (!importOWLs.empty()) {
for (std::vector<std::string>::iterator it = importOWLs.begin(),
ie = importOWLs.end(); it != ie; ++it) {
owl_file << "Import(" << ANGLEQUOTE(*it) << ")\n";
}
}
owl_file << "\n";
}
}
示例8: main
int main ()
{
//int posFlag = 0,velFlag = 0; // indicator to keep track of analysis function calls
while (std::getline(positionfile, line)) // Reading line by line
{
std::istringstream iss(line); // http://www.cplusplus.com/reference/sstream/istringstream/istringstream/
iss >> marker;
if ( marker == '$') {
//posFlag = 0;
//cout << "Read a special character $" << endl;
iss >> step >> filenum; // In position.txt file line beginning with $, ($ 1 1) = ($ step filenum)
cout << step << "\t" << filenum << endl;
filename = "postxtfiles/" + filenum + filetype; //postxtfiles is the directory in which i want to save it
//postxtfiles dir should exist in the current directory in which the program is running
cout << filename << endl;
PosFile.open(filename.c_str(), std::ofstream::out);
//PosFile << line << endl;
//cout << line << endl;
}
else if (marker == '#') {
示例9:
wesnoth_global_fixture()
{
using namespace boost::unit_test;
reporter.open("boost_test_result.xml");
assert( reporter.is_open() );
results_reporter::set_stream(reporter);
// lg::set_log_domain_severity("all",lg::debug());
game_config::path = filesystem::get_cwd();
// Initialize unit tests
SDL_Init(SDL_INIT_TIMER);
test_utils::get_fake_display(1024, 768);
gui2::init();
static const gui2::event::manager gui_event_manager;
// Set more report as default
#if BOOST_VERSION >= 106000
if(runtime_config::get<log_level>(runtime_config::LOG_LEVEL) == invalid_log_level)
unit_test_log.set_threshold_level(log_messages);
if(runtime_config::get<report_level>(runtime_config::REPORT_LEVEL) == INV_REPORT_LEVEL)
results_reporter::set_level(SHORT_REPORT);
unit_test_monitor.register_exception_translator<game::error>(&exception_translator_game);
unit_test_monitor.register_exception_translator<config::error>(&exception_translator_config);
#else
if(runtime_config::log_level() == invalid_log_level)
unit_test_log.set_threshold_level(log_messages);
if(runtime_config::report_level() == INV_REPORT_LEVEL)
results_reporter::set_level(SHORT_REPORT);
unit_test_monitor.register_exception_translator<game::error>(&exception_translator_game);
unit_test_monitor.register_exception_translator<config::error>(&exception_translator_config);
#endif
}
示例10: Log
// prints out the EMessageType , Class string , Method string , file path string , line string , current date string , and a message and apps to an file called Debuglog.txt
void Debug::Log(const EMessageType MsgType, const std::string& Class, const std::string& Method, const std::string& file, const int& line, const std::string& message) {
//clock objs
std::chrono::system_clock::time_point currenttime;
// initialize time_point
currenttime = std::chrono::system_clock::now();
//convert the currenttime obj into a time_t obj
static time_t debugTime = Debug::getCurrentTime(currenttime);
// file stream obj
static std::ofstream debugLog;
// open the stream obj
debugLog.open("debugLog.txt", std::ofstream::app | std::ofstream::out);
//switch statement using what type of message i should be getting
switch (MsgType) {
// for info print out the Class , Method of class , file path , which line the log was called , current time and date and a message regarding what could or is possibly happening
case EMessageType::INFO:
debugLog << "INFO: " << Class << "::" << Method << "() - " << "\n File :: " << file << "\n Line :: " << line << "\n Date :: " << ctime(&debugTime) << " Message :: " << message << "\n\n";
// break for next case
break;
// for warning print out the Class , Method of class , file path , which line the log was called , current time and date and a message regarding what could or is possibly happening
case EMessageType::WARNING:
debugLog << "WARNING: " << Class << "::" << Method << "() - " << "File :: " << file << ", Line :: " << line << ", Date :: " << ctime(&debugTime) << " Message :: " << message << "\n\n";
// break for next statement
break;
// for Error print out the Class , Method of class , file path , which line the log was called , current time and date and a message regarding what could or is possibly happening
case EMessageType::ERROR:
debugLog << "ERROR: " << Class << "::" << Method << "() - " << "File :: " << file << ", Line :: " << line << ", Date :: " << ctime(&debugTime) << " Message :: " << message << "\n\n";
// break for next statement
break;
// for FATAL_ERROR print out the Class , Method of class , file path , which line the log was called , current time and date and a message regarding what could or is possibly happening
case EMessageType::FATAL_ERROR:
debugLog << "FATAL ERROR: " << Class << "::" << Method << "() - " << "File :: " << file << ", Line :: " << line << ", Date :: " << ctime(&debugTime) << " Message :: " << message << "\n\n";
//final break
break;
}
//close the file
debugLog.close();
}
示例11: main
int main()
{
logfile.open("ai++.log", std::ios_base::out | std::ios_base::trunc);
if (!logfile.is_open()) {
std::cerr << "ai: cannot open log. terminating." << std::endl;
return 1;
}
RawBoard board;
uint8_t state;
AI ai;
while (true) {
read_board(std::cin, board);
read_state(std::cin, state);
AnalyzeResult result = ai.actuate(board);
if (std::get<1>(result)) {
std::cout << (uint8_t)std::get<0>(result) << std::flush;
} else {
std::cerr << "ai: no further options. terminating." << std::endl;
return 0;
}
}
}
示例12: main
int main(INT32 argc, CHAR **argv)
{
PIN_InitSymbols();
PIN_Init(argc, argv);
outfile.open("i18n_tool.out");
IMG img = IMG_Open(KnobUnicodeExeName.Value());
if (IMG_Valid(img) == TRUE)
{
string exeFullName = KnobUnicodeExeName.Value();
outfile << exeFullName.substr(exeFullName.rfind("/")+1) << endl;
IMG_Close(img);
}
IMG_AddInstrumentFunction(ImageLoad, 0);
PIN_AddFiniFunction(Fini, 0);
// Never returns
PIN_StartProgram();
return 0;
}
示例13: parse_args
int parse_args(int argc, char **argv)
{
int option;
while ((option = getopt(argc, argv,"l:")) != -1)
{
switch (option) {
case 'l' :
if(logger)
logger.close();
logger.open(optarg, std::ofstream::out | std::ofstream::app);
if (logger.fail()) {
cerr << "open failure as expected: " << strerror(errno) << '\n';
return -1;
}
break;
default :
usage();
return -1;
}
}
}
示例14: InitObjFile
void InitObjFile()
{
if (g_obj.is_open())
{
return;
}
std::ofstream file;
file.open("logger.obj");
if (file.is_open())
{
file.close();
}
g_obj.open("logger.obj", std::ios::app);
g_obj.setf(std::ios::fixed, std::ios::floatfield);
g_objFrameIndex = 0;
g_objObjectIndex = 0;
g_objVertexBaseIndex = 1;
g_objVertexIndex = 1;
}
示例15: main
int main(int argc, char *argv[])
{
if(argc==2){
double d = atof(argv[1]);
if(d!=0) amp = d;
else amp = 1000.0;
}
#ifdef FILE_SAVE
ptime now = second_clock::local_time();
std::string logname = to_iso_string(now) + std::string(".csv");
ofs.open(logname.c_str());
#endif /* FILE_SAVE */
port.set_option(serial_port_base::baud_rate(57600));
port.set_option(serial_port_base::character_size(8));
port.set_option(serial_port_base::flow_control(serial_port_base::flow_control::none));
port.set_option(serial_port_base::parity(serial_port_base::parity::none));
port.set_option(serial_port_base::stop_bits(serial_port_base::stop_bits::one));
boost::thread thr_io(boost::bind(&io_service::run, &io));
port.async_read_some( buffer(rbuf), boost::bind(&read_callback, _1, _2 ));
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA);
glutInitWindowSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
glutInitWindowPosition(0, 0);
window = glutCreateWindow("Value window");
glutDisplayFunc(&DrawGLScene);
glutIdleFunc(&DrawGLScene);
glutReshapeFunc(&ReSizeGLScene);
glutKeyboardFunc(&NormalKeyPressed);
glutSpecialFunc(&SpecialKeyPressed);
InitGL(DEFAULT_WIDTH, DEFAULT_HEIGHT);
glutMainLoop();
return 0;
}