本文整理汇总了C++中std::ofstream::flush方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::flush方法的具体用法?C++ ofstream::flush怎么用?C++ ofstream::flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ofstream
的用法示例。
在下文中一共展示了ofstream::flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LogHandler
void LogHandler( QtMsgType type, const char *msg )
{
static QMutex s_mutex;
QMutexLocker locker( &s_mutex );
switch( type )
{
case QtDebugMsg:
logfile << QTime::currentTime().toString().toAscii().data() << " Debug: " << msg << "\n";
break;
case QtCriticalMsg:
logfile << QTime::currentTime().toString().toAscii().data() << " Critical: " << msg << "\n";
break;
case QtWarningMsg:
logfile << QTime::currentTime().toString().toAscii().data() << " Warning: " << msg << "\n";
break;
case QtFatalMsg:
logfile << QTime::currentTime().toString().toAscii().data() << " Fatal: " << msg << "\n";
logfile.flush();
/*
cout << msg << "\n";
cout.flush();*/
abort();
break;
}
// std::cout << msg << "\n";
// cout.flush();
logfile.flush();
}
示例2: write_result
//write the result data to a file
void write_result(std::map<std::string, struct allRecord>& result,
struct configParam& configPam,
std::ofstream& out,
std::ofstream& out_detail)
{
int sum = configPam.qps * configPam.time;
std::string func[5] = {"set", "get", "del", "check_set", "check_del"};
std::string head_print[][7] = { {"hash_key_size", "sort_key_size", "value_size", "qps", "sum_data", "client_num"},
{trans(configPam.hashKeySize), trans(configPam.sortKeySize), trans(configPam.valueSize), trans(configPam.qps), trans(sum), trans(configPam.client_num) },
{"function", "success_num", "failure_num", "success_ratio", "avg_time(ms)"},
{"function", "fail_type", "fail_num"},
{"error", "hash_key", "sort_key", "value_get", "rel_value", "fail_type"}
};
out << "<table>";
write_to_file(head_print[0], 6, out, "th");
write_to_file(head_print[1], 6, out, "td");
out << std::endl;
write_to_file(head_print[2], 5, out, "th");
for(int i=0; i<5; i++) {
write_to_file(new std::string[5]{func[i], trans(sum - result[ func[i] ].fail_num), trans(result[ func[i] ].fail_num), trans((double)(sum - result[ func[i] ].fail_num) / sum * 100)+"%",
trans(result[ func[i] ].sum_time / sum) }, 5, out, "td");
}
bool is_print_head= true; //judge have the error or not
for(int i=0; i < 5; i++) {
struct allRecord temp = result[ func[i] ];
std::map<std::string, int> rec;
for(int j = 0; j < temp.fail_num; j++) {
if(is_print_head) {
is_print_head = false;
write_to_file(head_print[3], 3, out, "th class = 'errorStyle' ");
out_detail << "<table>";
write_to_file(head_print[0], 6, out_detail, "th");
write_to_file(head_print[1], 6, out_detail, "td");
write_to_file(head_print[4], 6, out_detail, "th");
}
rec[temp.fail_types[j] ]++;
write_to_file(new std::string[7]{func[i], temp.hash_keys[j], temp.sort_keys[j], temp.value_gets[j], generateValue(temp.sort_keys[j],
configPam.valueSize), temp.fail_types[j]}, 6, out_detail, "td");
}
std::map<std::string, int>::iterator it;
for(it = rec.begin(); it!=rec.end(); it++) {
write_to_file(new std::string[3]{func[i], it->first, trans(it->second)}, 3, out, "td");
}
}
if(!is_print_head) {
out_detail << "</table></br>";
}
out << "</table></br>";
out.flush();
out_detail.flush();
}
示例3: GameMain
int GameMain()
{
WriteStandardPaths();
EnumDirs();
WriteHeader("EnumFiles: kPath_Data");
EnumFiles(kPath_Data);
WriteHeader("EnumFiles: kPath_UserSave");
EnumFiles(kPath_UserSave);
{
ibFile<char> inFile = TestOpenData();
ibFile<char> outFile = TestOpenUser(inFile.Size());
while (!inFile.IsReady()) {}
if (!outFile.IsReady())
fout << "Outfile ready check failed!" << std::endl;
else
{
ibMemcpy(outFile.GetData(), inFile.GetData(), outFile.Size());
outFile.WriteFile();
}
while (!outFile.IsReady()) {}
}
fout.flush();
Sleep(1000);
fout.close();
return 0;
}
示例4: close
void Logger::close(){
if (logger_os.is_open()){
logger_os.flush();
logger_os.close();
logger_messageLevel = logNone;
}
}
示例5: WriteOutput
static void WriteOutput(double value) {
LOG_INFO("----------------------------------------------------------\n");
LOG_INFO("%d %f %d %d :: %lf", state.logging_type, ycsb::state.update_ratio,
ycsb::state.scale_factor, ycsb::state.backend_count, value);
auto& storage_manager = storage::StorageManager::GetInstance();
auto& log_manager = logging::LogManager::GetInstance();
// FIXME accumulate fsync count across all frontend loggers
auto frontend_logger = log_manager.GetFrontendLogger(0);
auto fsync_count = 0;
if (frontend_logger != nullptr) {
fsync_count = frontend_logger->GetFsyncCount();
}
LOG_INFO("fsync count : %d", fsync_count);
LOG_INFO("clflush count : %lu", storage_manager.GetClflushCount());
LOG_INFO("msync count : %lu", storage_manager.GetMsyncCount());
out << state.logging_type << " ";
out << ycsb::state.update_ratio << " ";
out << ycsb::state.scale_factor << " ";
out << ycsb::state.backend_count << " ";
out << value << "\n";
out.flush();
}
示例6:
void
DestinationTable::record_end ()
{
out << record_separator;
if (flush)
out.flush ();
}
示例7: msg
/// Prints a formatted message to stdout, optionally color coded
void Error::msg(MessageType messageType, const char *format, int color, va_list args) {
/// Skip messages where level is lower than minimum logging level
static char message[MAX_STRING_LEN];
vsnprintf(message, MAX_STRING_LEN - 1, format, args);
if ((int)messageType >= (int)minimumLoggingLevel) {
;
if (useColor) {
fprintf(stderr, "\x1b[0;%dm", color);
}
fputs(message, stderr);
if (useColor) {
fprintf(stderr, "\x1b[0m\n");
} else {
fprintf(stderr, "\n");
}
}
if (logfile.good()) {
switch (messageType) {
case MessageError: logfile << "ERR: "; break;
case MessageWarn: logfile << "WRN: "; break;
case MessageInfo: logfile << "INF: "; break;
case MessageDebug: logfile << "DBG: "; break;
}
logfile << message << std::endl;
logfile.flush();
}
}
示例8: logError
void logError(string msg,int GetLastError)
{
logger << msg << std::endl;
if(GetLastError!=0)
logger << "Error Code: " << WSAGetLastError() << std::endl;
logger.flush();
}
示例9: openLogfile
std::string openLogfile(std::ofstream &ofLog, const std::string &sAlgo, const std::string &sGrndtr, double threshold, const std::string &sFunction)
{
char cLogFilename[256];
char cTmp[256];
// Determine the name of the logfile
time_t rawtime;
struct tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(cTmp,256,"%Y-%m-%d_%H-%M-%S",timeinfo);
sprintf(cLogFilename,"log/%s_%s.log",cTmp,(sAlgo.substr(sAlgo.find_last_of('/')+1)).c_str());
std::string sLogFilename(cTmp);
sLogFilename += "_"+(sAlgo.substr(sAlgo.find_last_of('/')+1));
//sprintf(sLogFilename,"log/%s",sLogFilename);
printf("Log File: %s\n",cLogFilename);
if(!QDir("log").exists())
QDir().mkdir("log");
// Open logfile
ofLog.open(cLogFilename);
// Write logfile header
ofLog << cLogFilename << std::endl;
ofLog << std::endl;
ofLog << "Algorithm: " << sAlgo << std::endl;
ofLog << "Ground truth: " << sGrndtr << std::endl;
ofLog << "Threshold = " << threshold << std::endl;
ofLog << "Function = " << sFunction << std::endl;
ofLog << std::endl;
ofLog << "=====================================" << std::endl;
ofLog << std::endl;
ofLog.flush();
return sLogFilename;
}
示例10: end
void end(char*,std::size_t){
file
<<"{"
<<"\"type\":\"FeatureCollection\","
<<"\"features\":[";
bool done=false;
for(std::size_t idx=0;idx<lon.size()&&!done;++idx){
file
<<"{"
<<"\"type\":\"Feature\","
<<"\"geometry\":"
<<"{"
<<"\"type\":\"Point\","
<<"\"coordinates\":["<<lon[idx]<<","<<lat[idx]<<"]"
<<"}"
<<"}";
file.flush();
if((std::size_t)(file.tellp())+file_thresh>=file_lim)
done=true;
else
file<<",";
}
file
<<"]"
<<"}";
}
示例11: WriteOutput
static void WriteOutput() {
oid_t total_profile_memory = 0;
for (auto &entry : state.profile_memory) {
total_profile_memory += entry;
}
LOG_INFO("----------------------------------------------------------");
LOG_INFO("%lf %d %d :: %lf %lf %d",
state.scale_factor,
state.backend_count,
state.warehouse_count,
state.throughput,
state.abort_rate,
total_profile_memory);
out << state.scale_factor << " ";
out << state.backend_count << " ";
out << state.warehouse_count << " ";
out << state.throughput << " ";
out << state.abort_rate << " ";
out << total_profile_memory << "\n";
for (size_t round_id = 0; round_id < state.profile_throughput.size();
++round_id) {
out << "[" << std::setw(3) << std::left
<< state.profile_duration * round_id << " - " << std::setw(3)
<< std::left << state.profile_duration * (round_id + 1)
<< " s]: " << state.profile_throughput[round_id] << " "
<< state.profile_abort_rate[round_id] << " "
<< state.profile_memory[round_id] << "\n";
}
out.flush();
out.close();
}
示例12: flush
void Logger::flush()
{
if (g_logFile.is_open())
{
g_logFile.flush();
}
}
示例13: main
int main (int argc, char **argv)
{
DBGOPEN ("./testSplitString2.log");
try {
vector<string> samples;
samples.push_back ("104520,FIRST INSURANCE SOLUTIONS LTD,\"Unit 6, The Oaks Business Village\",Revenge Road,Lordswood,Chatham,Kent,ME5 8LF,UK");
samples.push_back ("104342,Towergate Risk Solutions (Lancaster),99 King Street,Lancaster,,,,LA1 1RH,UK");
samples.push_back ("104788,CU Insurance Consultants Ltd,1 Trevor Terrace,North Shields,Tyne & Wear,,,NE30 2DG,UK");
samples.push_back ("653,HOLMWOODS INSURANCE BROKERS LIMITED,LLOYDS,ONE LIME STREET,LONDON,,,EC3M 7HA,UK");
samples.push_back ("658,SNEATH KENT STUART LIMITED,\"LLOYDS OF LONDON INSURANCE,\",\"LLOYDS BUILDING,1 LIME STREET,\",LONDON,,,EC3M 7HA,UK");
samples.push_back ("663,E.J.WELTON,\"Lloyds Of London Insurance,\",\"Lloyds Building,1 Lime Street,\",London,,,EC3M 7HA,UK");
samples.push_back ("664,THOMPSON HEATH & BOND LTD,\"Murray House,Murray Road\",,,Orpington,,BR5 3QY,UK");
samples.push_back ("665,TOWERGATE STAFFORD KNIGHT & CO.LTD,55 Aldgate High Street,London,,,,EC3N 1AL,UK");
samples.push_back ("666,HOLMANS CONNECT,London Underwriting Centre,3 Minster Court,Mincing Lane,London,,EC3R 7DD,UK");
samples.push_back ("669,JOHN HOLMAN & SONS LTD,London Underwriting Centre,3 Minster Court,Mincing Lane,London,,EC3R 7DD,UK");
samples.push_back ("670,ROGER LARK & SEDGWICK,\"LLOYDS OF LONDON INSURANCE,\",\"LLOYDS BUILDING,1 LIME STREET,\",LONDON,,,EC3M 7HA,UK");
samples.push_back ("104557,Willis & Company (Insurance Brokers) Ltd,55-59 Donegall Street,Belfast,Co Antrim,,,BT1 2FH,UK");
samples.push_back ("104585,Lionheart Insurance Services Ltd,Radio House,Aston Road North,Birmingham,,,B6 4DA,UK");
samples.push_back ("105097,Oamps (UK) Ltd (Wholesale),Windsor House,High Street,Esher,,,KT10 9RY,UK");
samples.push_back ("104837,Lansdowne Woodward Ltd,Princes Court,Princes Road,Ferndown,,,BH22 9JG,UK");
samples.push_back ("104676,P J Mcilroy & Son Insurance & Investment,13 Ann Street,Ballycastle,Co. Antrim,,,BT54 6AA,UK");
samples.push_back (",,,,,,,,");
samples.push_back ("104980,D N Paterson & Company,17 Sandhead Road,Strathaven,Lanarkshire,,,ML10 6HX,UK");
samples.push_back ("104692,Sterling General Insurance Services Ltd,81 Albany Street,Regents Park,,,,NW1 4BT,UK");
string seps(",");
string encs("\"");
unsigned int i_count = 0;
vector<string> toks3;
vector<string>::iterator t; // token iterator
vector<string>::const_iterator s = samples.begin(); // sample iterator.
while (s != samples.end()) {
toks3.clear();
toks3 = futil::splitStringWithEncs (*s, seps, encs);
cout << "Output of splitStringWithEncs for the string:" << endl;
// A count line:
cout << "!123456789\"123456789£123456789$123456789\%123456789^123456789&123456789*123456789(123456789)123456789" << endl << *s << endl;
i_count = 0;
for (t = toks3.begin(); t != toks3.end(); t++) {
cout << (i_count++) << ". " << *t << "\n";
}
++s;
}
} catch (const exception& e) {
// handle error condition; should catch any
// exception thrown above
DBGSTREAM << "Exception: '" << e.what() << "'\n";
cerr << "Exception: '" << e.what() << "'\n";
DBGSTREAM.flush();
}
DBGCLOSE();
_exit(0);
}
示例14: WriteProfiles
void WriteProfiles(int in, int layer)
{
double parentavgms;
if(in == -1)
{
char fullpath[MAX_PATH+1];
FullPath("profiles.txt", fullpath);
g_profF.open(fullpath, std::ios_base::out);
parentavgms = g_profile[TIMER_FRAME].averagems;
}
else
{
parentavgms = g_profile[in].averagems;
}
double ofparentpct;
double totalms = 0;
double totalofparentpct = 0;
double percentage;
int subprofiles = 0;
for(int j=0; j<TIMERS; j++)
{
if(g_profile[j].inside != in)
continue;
totalms += g_profile[j].averagems;
}
for(int j=0; j<TIMERS; j++)
{
if(g_profile[j].inside != in)
continue;
percentage = 100.0 * g_profile[j].averagems / totalms;
ofparentpct = 100.0 * g_profile[j].averagems / parentavgms;
totalofparentpct += ofparentpct;
subprofiles++;
for(int k=0; k<layer; k++)
g_profF<<"\t";
g_profF<<g_profile[j].name<<"\t...\t"<<g_profile[j].averagems<<"ms per frame, "<<percentage<<"% of this level's total"<<std::endl;
WriteProfiles(j, layer+1);
}
if(subprofiles > 0)
{
for(int k=0; k<layer; k++)
g_profF<<"\t";
g_profF<<"level total sum: "<<totalms<<" ms per frame, that means "<<totalofparentpct<<"% of this parent's duration underwent profiling"<<std::endl;
}
if(in == -1)
g_profF.flush();
}
示例15: finish
void Logger::finish()
{
if (g_logFile.is_open())
{
g_logFile.flush();
g_logFile.close();
}
}