Exemplo n.º 1
1
void a::fileclose(ofstream &out, Error &error) {
  if (out.fail()) {
    error.addwarning(10,15,"Misc","Error writing to output file!");
    error.writewarnings();
  }
  out.close();
}
Exemplo n.º 2
0
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);
    }
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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();
}
Exemplo n.º 6
0
/****************************************************************************
Function name: openOutputDataFile

Description:   Open data file "Monsters.out". Exit program if file 
               cannot be opened for output.

Parameters:    (ofstream&) outStream is the data file stream.

Returns:       (outStream passed by reference).
****************************************************************************/
void openOutputDataFile(ofstream& outStream) {
  outStream.open("monsters.out");
  if (outStream.fail()) {
	cout << "Cannot open file monsters.out!\n";
	exit(1);
  }
}
Exemplo n.º 7
0
void writeFile(ofstream& fout) {
	fout.open("prettysonglist.txt");
	if(fout.fail()) {
		cout << "Couldn't write to file." << endl;
		exit(-1);
	}
}
Exemplo n.º 8
0
// 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);
	}

}
Exemplo n.º 9
0
 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); 
   }
 }
Exemplo n.º 10
0
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();
}
Exemplo n.º 11
0
void openwritefile(ofstream& OutStream, string thefilename)
{
    OutStream.open(thefilename.c_str());
    if (OutStream.fail())
    {
        cout << "can't open the file: " << thefilename << endl;
        exit(1);
    }
}
Exemplo n.º 12
0
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;
}
Exemplo n.º 13
0
 //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);
     }        
 }
//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;
}
//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 ;
}
Exemplo n.º 16
0
void FileClass::connectOutputFile(ofstream & outputFile)
{
	string filename;
	getline(cin, filename);

	outputFile.open(filename);

	if (outputFile.fail()) {
		throw outputFileFail(filename); 
	}
}
Exemplo n.º 17
0
void ofstrOpen (std::string fileName, std::string errorID, Parameters *P, ofstream & ofStream) {//open file 'fileName', generate error if cannot open
    ofStream.open(fileName.c_str(), std::fstream::out | std::fstream::trunc);
    if (ofStream.fail()) {//
//         dir1=fileName.substr(0,fileName.find_last_of("/")+1);
//         if (dir1=="") dir1="./";
        ostringstream errOut;
        errOut << errorID<<": exiting because of *OUTPUT FILE* error: could not create output file "<< fileName <<"\n";
        errOut << "Solution: check that the path exists and you have write permission for this file\n";
        exitWithError(errOut.str(),std::cerr, P->inOut->logMain, EXIT_CODE_FILE_OPEN, *P);
    };    
};
Exemplo n.º 18
0
/********************************
** Function: void openOutFile(ofstream &fout, string str);
** Description: Open the output file and check for errors
**  throw exception if file open fails
**
**
** Parameters: ofstream fout is the file handle
**  string str is the name of the file to open
**
** pre-conditions: fout has been declared, str is a valid file name
** post-conditions: file opened and checked for errors in opening
********************************/
void openOutFile(ofstream &fout, char str[])
{
     fout.open(str);
     if (fout.fail())
     {
          cout << "SOMETHING WENT TERRIBLY WRONG! FAILED TO OPEN OUTPUT FILE"
               << endl;
          throw(-1);
     }
     return;
}
Exemplo n.º 19
0
string promptUserForFile(ofstream & stream, string prompt) {
   while (true) {
      cout << prompt;
      string filename;
      getline(cin, filename);
      openFile(stream, filename);
      if (!stream.fail()) return filename;
      stream.clear();
      cout << "Unable to open that file.  Try again." << endl;
      if (prompt == "") prompt = "Output file: ";
   }
}
Exemplo n.º 20
0
/** Returns a stream for writing to this file. Parent directories will be created if necessary.
* @param append If false, this file will be overwritten if it exists, otherwise it will be appended.
* @throw GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or
*        {@link FileType#Internal} file, or if it could not be written. */
void FileHandle::write(bool append, ofstream& stream) const
{
	FileHandle parentHandle = parent();
	parentHandle.mkdirs();

	std::ios_base::openmode mode;
	mode = append? ios_base::out | ios_base::app: ios_base::out | ios_base::trunc;
	stream.open(m_strFullPath.c_str(), mode);
	if(stream.fail())
	{
		throw GdxRuntimeException("Error writing file: " + m_strFullPath);
	}
}
Exemplo n.º 21
0
void outputFileCheck(ofstream &fout, string filename)
{
    //Declare and open output file
    fout.open(filename.c_str());

    //Print an error if that failed
    if(fout.fail())
    {
        cerr << "Unable to open " << filename << endl;
        //Exit with errors
        exit(2);
    }
}
Exemplo n.º 22
0
bool InitLog(string filename, ofstream& logfile)
{
  if (!getenv("HOME"))
  {
    PrintError("$HOME is not set");
    return false;
  }
  
  string fullpath;

  if (filename.find("/") == string::npos)
  {
    string directory = static_cast<string>(getenv("HOME")) + "/.boblight/";
    fullpath = directory + filename;

    //try to make the directory the log goes in
    if (mkdir(directory.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1)
    {
      //if it already exists we're ok
      if (errno != EEXIST)
      {
        PrintError("unable to make directory " + directory + ":\n" + GetErrno());
        return false;
      }
    }
  }
  else
  {
    fullpath = filename;
  }

  //we keep around 5 old logfiles
  for (int i = 4; i > 0; i--)
    rename(string(fullpath + ".old." + ToString(i)).c_str(), string(fullpath + ".old." + ToString(i + 1)).c_str());

  rename(fullpath.c_str(), string(fullpath + ".old.1").c_str());

  //open the logfile in append mode
  logfile.open(fullpath.c_str());
  if (logfile.fail())
  {
    PrintError("unable to open " + fullpath + ":\n" + GetErrno());
    return false;
  }

  Log("start of log %s", fullpath.c_str());

  return true;
}
Exemplo n.º 23
0
void OpenFiles (ifstream &Inp, ofstream &Out)
{
   char Fname[255];

   do
   {
      cout << "Input file name: " << flush;
      cin.getline(Fname, 255);
      Inp.clear();
	  Inp.open(Fname, ios::in); //Inp.open(Fname, ios::in|ios::nocreate);
	  if (Inp.fail())
         cout << "Failed to open " << Fname << " --- try again\n";
   } while ( Inp.fail() );

   do
   {
      cout << "Output file name:  " << flush;
      cin.getline(Fname, 255);
      Out.clear();
      Out.open(Fname);
      if (Out.fail())
         cout << "Failed to open hw2output.txt  " << Fname << " --- try again\n";
   } while ( Out.fail() );
}
Exemplo n.º 24
0
//Writes a message to the admin log
//Input:
//	message: message to write to log
void writeToAdminLog(const char *message) {
	char timestamp[TIMESTAMP_LEN] = "";
	time_t timeSt;
	
	QRAssert((message != NULL), "writeToAdminLog", "NULL passed as message");
	
	timeSt = time(NULL);
	//get timestamp
	strftime(timestamp, TIMESTAMP_LEN, "%Y-%m-%d %H:%M:%S", localtime(&timeSt));
	
	g_AdminLogFile<<timestamp<<" "<<g_ipAddrStr<<" "<<message<<"\n"<<endl;
	QRAssert((!g_AdminLogFile.fail()), "ostream::operator<<", "Unable to write to administrative log");
	
	return;
}
Exemplo n.º 25
0
void openFiles(char *argv[], ifstream &in, ofstream &out)
{
	in.open(argv[1]);
	if (in.fail())
	{
		cerr << endl << "*** ERROR: Can not open " << argv[1] << " for input." << endl;
		exit(0);
	}

	out.open(argv[2]);
	if (out.fail())
	{
		cerr << endl << "*** ERROR: Can not open " << argv[2] << " for output." << endl;
		exit(0);
	}
}
void process_name(ifstream& in_file, double& total, ofstream &out)
{
	string name;
	int count;
	double percent;
	in_file >> name >> count >> percent;
	if (in_file.fail()) {
		cout << "Error processing name." << endl;
		cin.get();
		return;
	} // Check for failure after each input
	if (out.fail()) {
		cout << "Error process_name writing to file";
	}
	if (total > 0) {
		cout << name << " ";
		out << name << " ";
	}
	total = total - percent;
}
Exemplo n.º 27
0
//FUNCTION DEFINITIONS
void openStreams(ifstream & fin_par, ofstream & fout_par)
{
    string infile, outfile;
    cout << "\nPlease enter the name of your input file:\n";
    cin >> infile;
    cout << "\nPlease enter the name of your output file:\n";
    cin >> outfile;

 fin_par.open(infile);
 if(fin_par.fail())
 {
     cout << "\nFailed to open input file.";
     exit(1);
 }
 fout_par.open(outfile);
 if(fout_par.fail())
 {
     cout << "\nFailed to open output file.";
     exit(1);
 }
}
Exemplo n.º 28
0
// Input:   argc  - the number of arguments on the command line
//          argv  - the argument vector
// Output:  ifs   - the opened input file stream
//          ofs   - the opened output file stream
bool openfiles(int argc,char *argv[],ifstream &ifs,ofstream &ofs)
{
   if (argc != 3)  // check to see that there are 3 command line args
   {
      cerr << "usage:  " << argv[0] << " <inputfile> <outputfile>\n";
      return false;
   }
   ifs.open(argv[1]);   // open the input file
   if (ifs.fail())
   {
      cerr << "error opening inputfile: '" << argv[1] << "' doesn't exist?\n";
      return false;
   }
   ofs.open(argv[2]);   // open the output file
   if (ofs.fail())
   {
      cerr << "error opening outputfile\n";
      return false;
   }
   return true;        // opening the files was successful
}
void Node::initialize()
{
    elapsed_time = 0.0;
    total_time = 0.0;
    latency_target = 0.0;
    cycles_executed = 0.0;
    freq_nominal = 0.0;
    size = 0.0;
    arrival_time = 0.0;
    start_time = 0.0;
    freq = freq_min;
    KI = 0.5;
    KP = 1.0;
    energy = 0.0;
    error_total = 0.0;
    ofs.open("frequencies");
    if (ofs.fail())
        EV << "Couldn't open file for writing" << '\n';
    simstep_msg = new cMessage("SimulationStep");
    scheduleAt(simTime() + static_cast<simtime_t>(delta_sim), simstep_msg);
}
Exemplo n.º 30
0
void escribirFichero (char * nombre_archivo_entrada, ofstream & archivo_salida){

  ifstream archivo_entrada;
  string linea;
  
  archivo_entrada.open(nombre_archivo_entrada); 
    
  if (archivo_entrada.fail()){ //si el archivo no se pudo abrir
    cout << "\n\nEl archivo de entrada no se abrio correctamente\n\n" << endl;
    exit(0);
  }
  if (archivo_salida.fail()){ //si el archivo no se pudo abrir
    cout << "\n\nEl archivo de salida no se abrio correctamente\n\n" << endl;
    exit(0);
  }

  while (getline(archivo_entrada, linea))
    archivo_salida << linea << endl;

  archivo_entrada.close();
  
  return;
}