本文整理汇总了C++中ofstream::fail方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::fail方法的具体用法?C++ ofstream::fail怎么用?C++ ofstream::fail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofstream
的用法示例。
在下文中一共展示了ofstream::fail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fileclose
void a::fileclose(ofstream &out, Error &error) {
if (out.fail()) {
error.addwarning(10,15,"Misc","Error writing to output file!");
error.writewarnings();
}
out.close();
}
示例2: TryOpen
static void TryOpen(ofstream& f, const char* name){
f.open(name);
f.setf(ios::showbase);
if (f.fail()){
ErrorExit("cannot open output file: " << name, MetasimError_FileOp);
}
}
示例3: DllMain
BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID)
{
if (reason == DLL_PROCESS_ATTACH) {
original = LoadLibraryA("s7onlinx_.dll");
if (original == 0) {
return false;
}
original_send = GetProcAddress(original, "SCP_send");
original_receive = GetProcAddress(original, "SCP_receive");
determine_proxy_session();
logfile.open(absolute_logfile_name, ofstream::out);
if (logfile.fail()) {
return false;
}
pcap_send = unique_ptr<Pcap>(new Pcap(absolute_sendcap_filename));
pcap_recv = unique_ptr<Pcap>(new Pcap(absolute_recvcap_filename));
pcap_amalgamation = unique_ptr<Pcap>(new Pcap(absolute_amalgamationcap_filename));
log("Proxy initialized");
} else if (reason == DLL_PROCESS_DETACH) {
log("Proxy shutdown");
FreeLibrary(original);
}
return true;
}
示例4: switch_log
static bool switch_log(ofstream &flog)
{
GenerateTime("pacs_log\\%Y\\%m\\%d\\%H%M%S_service_n.txt", buff, sizeof(buff));
if(flog.tellp() > 10 * 1024 * 1024 || strncmp(buff, current_log_path.c_str(), 20)) // 20 == strlen("pacs_log\\YYYY\\MM\\DD\\")
{
if(PrepareFileDir(buff))
{
if(flog.is_open())
{
time_header_out(flog) << "to be continued" << endl;
flog.close();
}
flog.open(buff);
if(flog.fail())
{
cerr << "watch_notify() switch log " << buff << " failed" << endl;
return false;
}
time_header_out(flog) << "continuation of " << current_log_path << endl;
current_log_path = buff;
}
else
{
DWORD gle = GetLastError();
cerr << "watch_notify() switch log failed, PrepareFileDir(" << buff << ") failed" << endl;
return false;
}
}
return true;
}
示例5: writeOut
bool HogWrapper::writeOut(ofstream &ofs)
{
ofs << "<svlFeatureExtractor id=\"HogWrapper\" ";
ofs << " version=\"1.0\" ";
ofs << " width=\"" << _hog->winSize.width << "\" ";
ofs << " height=\"" << _hog->winSize.height << "\" ";
ofs << " blockWidth=\"" << _hog->blockSize.width << "\" ";
ofs << " blockHeight=\"" << _hog->blockSize.height << "\" ";
ofs << " blockStrideX=\"" << _hog->blockStride.width << "\" ";
ofs << " blockStrideY=\"" << _hog->blockStride.height << "\" ";
ofs << " nBins=\"" << _hog->nbins << "\" ";
ofs << " derivAperture=\"" << _hog->derivAperture<<"\" ";
ofs << " winSigma=\"" << _hog->winSigma<<"\" ";
ofs << " histogramNormType=\"" << _hog->histogramNormType << "\" ";
ofs << " L2HysThreshold=\"" << _hog->L2HysThreshold << "\" ";
ofs << " gammaCorrection=\""<< (bool) _hog->gammaCorrection<<"\" ";
ofs << " validChannel=\""<<_validChannel<<"\" ";
ofs << " cellWidth=\""<<_hog->cellSize.width<<"\" ";
ofs << " cellHeight=\""<<_hog->cellSize.height<<"\" ";
ofs << "> " << endl;
ofs << "</svlFeatureExtractor>" << endl;
return !ofs.fail();
}
示例6: writeFile
void writeFile(ofstream& fout) {
fout.open("prettysonglist.txt");
if(fout.fail()) {
cout << "Couldn't write to file." << endl;
exit(-1);
}
}
示例7: openFiles
// open input and output files
// pre: user is prepared to enter file names at the keyboard
// post: files have been opened
void openFiles(ifstream &infile, ofstream &outfile)
{
// open input data file
string inFileName;
cout << "Enter the name of the input file: ";
cin >> inFileName;
infile.open(inFileName.c_str());
if (infile.fail()) {
cout << "Error opening input data file" << endl;
char junk;
cout << "press enter to exit";
junk = cin.get();
junk = cin.get();
exit(1);
}
// open output data file
string outFileName;
cout << "Enter the name of the output file: ";
cin >> outFileName;
outfile.open(outFileName.c_str());
if (outfile.fail()) {
cout << "Error opening output data file" << endl;
char junk;
cout << "press enter to exit";
junk = cin.get();
junk = cin.get();
exit(1);
}
}
示例8: open
inline void open(const char *fn, ios_base::openmode mode) {
s_fn.reset(fn);
ofs.open(fn, mode);
if (ofs.fail()) {
throw new AzException(AzFileIOError, "AzOfs::open", "Failed to open:", fn);
}
}
示例9: main
int main()
{
mapgen.open("mapgen.txt");
if (mapgen.fail())
{
cout << "can't open file" << endl;
return 0;
}
srand(time(NULL));
const int X = 20, Y = 20; //dimensions of the maze
int **checkWall; //ptr to the two-dimensional array that determines walls and spaces
int **checkVisited; //ptr to the two-dimensional array that stores whether a coordinate has been looked at
checkWall = new int*[X]; //setting up the arrays to make the maze
checkVisited = new int*[X]; //
//
for (int i = 0; i < X; i++) //
{ //
checkWall[i] = new int[X]; //
checkVisited[i] = new int[X]; //
for (int i = 0; i<Y; i++) //
{ //
checkWall[i] = new int[Y]; //
checkVisited[i] = new int[Y]; //
} //
} //
initMap(X, Y, checkWall, checkVisited); // fills map with solid walls, sets checkVisited to zero(false) for all coordinates
mapGen(checkWall, checkVisited, X, Y); // generates the maze!
for (int i = 0; i<20; i++) //prints the maze to the screen, 'HHH' for wall, ' ' for space
{ //
for (int j = 0; j < X; j++) { //
if (checkWall[i][j]) //
cout << "HHH"; //
else //
cout << " "; //
} //
cout << "HHH" << endl; //
} //
for (int i = -1; i < Y; i++) //
if (i == Y - 2) //
cout << " "; //
else //
cout << "HHH"; //
cout << endl; //
for (int j = 0; j < X; j++) //deleting the zombies that made the maze
{ //
delete[] checkWall[j]; //
delete[] checkVisited[j]; //
} //
delete[] checkWall; //
delete[] checkVisited; //
mapgen.close();
}
示例10: openwritefile
void openwritefile(ofstream& OutStream, string thefilename)
{
OutStream.open(thefilename.c_str());
if (OutStream.fail())
{
cout << "can't open the file: " << thefilename << endl;
exit(1);
}
}
示例11: open_file
void result::open_file()
{
input.open(file_name);
output.open("A.cht");
if(input.fail())//if open fail,then finish
{
cout<<"Input file open fail"<<endl;
exit(1);
}
if(output.fail())
{
cout<<"Output file open fail"<<endl;
exit(1);
}
if(!input.fail() && !output.fail())
cout<<"All file open success"<<endl;
}
示例12: openFile
//Opens an output file that will contain a time series for N
void openFile()
{
ostringstream os;
os << "window_N=" << _N0 << ".txt";
_ofile.open(os.str().c_str(), ios::app);
if (_ofile.fail()) {
cerr << "ERROR: Failed to open window " << _N0 << ".\n";
exit(0);
}
}
示例13: open_ofstream
//creates the file that will have the changes
void open_ofstream (ofstream& name)
{
name.open("C:\\Users\\Mufasa\\Desktop\\ENGLISH_AS_A_SECOND_LANGUAGE_aww_yeah_baby.rtf");
if (name.fail())
{
cout << "Failed to connect to file & this program probaly did not create the file for you\n";
system ("PAUSE");
exit(1);
}
return;
}
示例14: open_ofstream_isd
//Connects to the file in the same directory
void open_ofstream_isd(ofstream& name)
{
name.open("Nicely_formatted_text.txt");
if (name.fail())
{
cout << "Failed to connect to file [middle finger]\n Perhaps the file is not in the same folder as the program";
system ("PAUSE");
exit(1);
}
return ;
}
示例15: connectOutputFile
void FileClass::connectOutputFile(ofstream & outputFile)
{
string filename;
getline(cin, filename);
outputFile.open(filename);
if (outputFile.fail()) {
throw outputFileFail(filename);
}
}