本文整理汇总了C++中std::fstream::close方法的典型用法代码示例。如果您正苦于以下问题:C++ fstream::close方法的具体用法?C++ fstream::close怎么用?C++ fstream::close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::fstream
的用法示例。
在下文中一共展示了fstream::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Fini
VOID Fini(INT32 code, VOID *v) {
PRINT_SCN ("All applications are at the end" << "...");
#ifdef LOG_ASSEM
TraceFile.close();
#endif
MemFile.close();
}
示例2: createWalletFile
void createWalletFile(std::fstream& walletFile, const std::string& filename) {
walletFile.open(filename.c_str(), std::fstream::in | std::fstream::out | std::fstream::binary);
if (walletFile) {
walletFile.close();
throw std::runtime_error("Wallet file already exists");
}
walletFile.open(filename.c_str(), std::fstream::out);
walletFile.close();
walletFile.open(filename.c_str(), std::fstream::in | std::fstream::out | std::fstream::binary);
}
示例3: saveAllCellsToCsv
void ScientificProcessor::saveAllCellsToCsv(std::fstream &filestr)
{
std::map<int, std::vector<double> > firstTime = allCells.begin()->second;
std::vector<double> firstCell = firstTime.begin()->second;
std::cout << firstCell.size() << std::endl;
int nfl = (firstCell.size() - 9)/2;
/* Header */
filestr << "t, label, tp, parent, cx, cy, h, w, area, angle, ";
for(unsigned int i = 0; i < nfl; i++)
filestr << "flav" << i << ", flsd" << i << ", ";
filestr << std::endl;
/* Data */
for(std::map<int, std::map<int, std::vector<double> > >::iterator it = allCells.begin();
it != allCells.end(); ++it) {
int t = it->first;
std::map<int, std::vector<double> > currentTime = it->second;
for(std::map<int, std::vector<double> >::iterator itm = currentTime.begin();
itm != currentTime.end(); ++itm) {
std::vector<double> features = itm->second;
filestr << t << ",";
for(std::vector<double>::iterator itv = features.begin();
itv != features.end(); ++itv) {
filestr << *itv << ",";
}
filestr << std::endl;
}
}
filestr.close();
}
示例4: open
void open() {
//
// open file in out mode, close and open again in out/in mode
//
for (int ilayer=0; ilayer<4; ++ilayer) {
vname[ilayer] << "temporary_file_v" << ilayer << "file-" << std::setfill('0') << std::setw(3) << angle << ".dat";
tname[ilayer] << "temporary_file_t" << ilayer << "file-" << std::setfill('0') << std::setw(3) << angle << ".dat";
uname[ilayer] << "temporary_file_u" << ilayer << "file-" << std::setfill('0') << std::setw(3) << angle << ".dat";
vfile[ilayer] = new fstream(vname[ilayer].str().c_str(), std::ios::binary | std::ios::out);
vfile[ilayer]->close();
vfile[ilayer]->open(vname[ilayer].str().c_str(), std::ios::binary | std::ios::in | std::ios::out);
tfile[ilayer] = new fstream(tname[ilayer].str().c_str(), std::ios::binary | std::ios::out);
tfile[ilayer]->close();
tfile[ilayer]->open(tname[ilayer].str().c_str(), std::ios::binary | std::ios::in | std::ios::out);
ufile[ilayer] = new fstream(uname[ilayer].str().c_str(), std::ios::binary | std::ios::out);
ufile[ilayer]->close();
ufile[ilayer]->open(uname[ilayer].str().c_str(), std::ios::binary | std::ios::in | std::ios::out);
}
wname << "temporary_file_wfile-" << std::setfill('0') << std::setw(3) << angle << ".dat";
wfile = new fstream(wname.str().c_str(), std::ios::binary | std::ios::out);
wfile->close();
wfile->open(wname.str().c_str(), std::ios::binary | std::ios::in | std::ios::out);
}
示例5: getFILE
// getFILE is a wrapper for getting files
bool getFILE(std::fstream &fp, const char* fname, const char* mode)
{
int writeFile = 0;
if (strcmp(mode, "out") == 0)
{
writeFile = 1;
if(writeFile && fexists(fname))
{
fprintf(stderr,"File already exists: %s\n",fname);
return false;
}
fp.open(fname, std::ios::out);
}
else if (strcmp(mode, "app") == 0)
fp.open(fname, std::ios::app);
else if (strcmp(mode, "in") == 0)
fp.open(fname, std::ios::in);
if( !fp )
{
fprintf(stderr,"Error opening FILE handle for file: %s\n",fname);
fp.close();
return false;
}
return true;
}
示例6: file
void
getstat(const std::string& pid,std::fstream& tsdbfile,std::string metric)//Get memmemory information (in one block right now)
{
std::string dummy,minflt,mjflt,utime,s_time,nthreads,vsize,rss,iodelay;
char state;
std::string path="/proc/"+pid+"/stat";
std::ifstream file(path,std::ifstream::binary);
file>>dummy>>dummy>>state>>dummy>>dummy>>dummy>>dummy>>dummy>>dummy>>minflt>>dummy>>mjflt>>dummy>>utime>>s_time>>dummy>>dummy>>dummy>>dummy>>nthreads>>dummy>>dummy>>vsize>>rss;
metric+=".stat";
std::string st_int;
switch(state){
case 'R':
st_int="1";break;
case 'S':
st_int="2"; break;
case 'D':
st_int="3"; break;
case 'T':
st_int="4"; break;
default:
st_int="0";
}
tsdbfile.open ("tcollector_proc.out",std::fstream::app);
tsdb_stdout(tsdbfile,metric+".state",st_int);
tsdb_stdout(tsdbfile,metric+".minflt",minflt);
tsdb_stdout(tsdbfile,metric+".mjrflt",mjflt);
tsdb_stdout(tsdbfile,metric+".utime",utime);
tsdb_stdout(tsdbfile,metric+".stime",s_time);
tsdb_stdout(tsdbfile,metric+".nthreads",nthreads);
tsdbfile.close();
return;
}
示例7: Close
exp bool Close() {
// Update FS info before unmounting the disk
WriteFSInfo();
f.close();
return true;
}
示例8: verifiedOC
// Ensures the file is opened/closed properly and retries 5 times.
// if choice is false, the file is closed and if it is 1, the file is opened.
bool verifiedOC ( std::fstream& file, std::string fileDir, bool choice, std::ios::openmode io ) {
unsigned int i = 0; // Declaring a counter variable.
// Choice determines if we are opening or closing the file. (True to open, False to close)
if ( choice ) {
do {
file.open ( fileDir.c_str(), io ); // Open file as user selection.
if ( file.is_open() ) {
return true;
} else {
// Prints that the attempt to change the file state has failed.
std::cout << "The file " << fileDir.c_str() << " failed to open... Retrying " << ++i << "\n";
}
// Will exit the loop after the the number of attempts FILE_OPEN_RETRIES specifies.
if ( i >= FILE_OPEN_RETRIES ) {
std::cout << "The file " << fileDir.c_str() << " failed to change open." << std::endl;
return false;
}
} while ( !file.is_open() );
} else {
file.close();
}
return true;
}
示例9: StoreCurrentFitnessInPopulation
void StoreCurrentFitnessInPopulation(Fitnesses& fitness, std::fstream& fitnessEachGeneration) {
fitnessEachGeneration.open("FitnessEachGeneration.txt", std::fstream::in | std::fstream::out | std::fstream::app);
int populationSize = fitness.size();
for(int i=0;i<populationSize;i++) {
fitnessEachGeneration << fitness[i] <<'\n';
}
fitnessEachGeneration.close();
}
示例10: close
void close() {
for (int ilayer=0; ilayer<4; ++ilayer) {
vfile[ilayer]->close();
tfile[ilayer]->close();
ufile[ilayer]->close();
}
wfile->close();
}
示例11: write_file
void PcieAccessInterfaceTest::write_file(char* data, const std::string& path, uint32_t size, uint32_t offset) {
memory_file.open(path, std::ios::out |std::ios::binary | std::ios::trunc);
if (memory_file.is_open()) {
memory_file.seekg(offset, std::ios::beg);
memory_file.write(data, size);
memory_file.close();
}
}
示例12: createAndOpen
void createAndOpen(std::fstream& file, std::string name){
if (!exists(name.c_str())){
file.open(name.c_str(), std::fstream::out |
std::fstream::binary);
file.close();
}
file.open(name.c_str(), std::fstream::in | std::fstream::out |
std::fstream::binary);
}
示例13: finishwithfile
/*! \brief Close and truncate the file, and update digest
* Truncation is needed to remove any detritus from previously-saved states.
*/
void resultsfile::finishwithfile(std::fstream& file)
{
std::streampos length = file.tellp();
// close and truncate file
file.close();
truncate(length);
// re-open and update digest
file.open(fname.c_str(), std::ios::in);
filedigest.process(file);
}
示例14: NMPRK_StopDebugLogging
NMPRKC_API nmprk_status_t NMPRK_StopDebugLogging()
{
if(si_fsDebugLog.is_open() == true)
{
SI_DEBUG_INFO(SI_THIS_MODULE, "Debug Logging Stopped");
si_fsDebugLog.close();
}
return NMPRK_SUCCESS;
}
示例15: init
/**
* Initializes the hash function, with a file stream value.
*
* @param fileStream The stream value to be used for computation.
* @param closeStream If the file stream should be closed at end, if false
* the file stream is positioned at the initial position.
*/
void HashFunction::init(std::fstream &fileStream, bool closeStream) {
// calls the stream init method
this->init((std::istream &) fileStream);
// in case the file stream should be closed
if(closeStream) {
// closes the file stream
fileStream.close();
}
}