예제 #1
0
void sinistra(char *testo[],int righe)
{ // è il classico modo di scrivere 
	input.open(testo[1],ios::in);
	char c;
	while(input.get(c)) // prende il carattere...
	{
	cout << c; // e lo scrive 
	}
	input.close();
}
예제 #2
0
bool Logger::openLog(fstream &file, const string &name)
{
	file.open(name.c_str(), ios::out | ios::app);
	if (file.is_open())
	{
		file.seekp(0, ios::end);
		return true;
	}
	return false;
}
예제 #3
0
    void writefile(fstream& fout,string fname)
    {
        fout.close();
        fout.open(fname.c_str(),ios::out);

        for(int i=0; i<t; i++)
        {
            wfile(fout,root,i+1);
        }
    }
예제 #4
0
         /*******************************************
         * mainTitleMessage()
         * fancy stuff :D
         *******************************************/
        void mainTitleMessage() 
        {
			file.open("coredump.txt", ios::out | ios::app);
            file<<"======================================"<<endl;
            file<<"==        CODENAME: xSoko mobile    =="<<endl;
            file<<"==          Text output             =="<<endl;
            file<<"======================================"<<endl;
            file<<endl;
			file.close();
        }
예제 #5
0
파일: files.cpp 프로젝트: kejn/job-shop-HGA
void openFile(fstream &file, const string &fileName,
		const std::ios_base::openmode openmode) throw (string) {
	file.open(fileName.c_str(), openmode);
	if (file.bad()) {
		if (file.is_open()) {
			file.close();
		}
		string message = "Nie udalo sie otworzyc pliku \"" + fileName + "\"";
		throw message;
	}
}
예제 #6
0
void input() {
	fin.open("from.from", ios_base::in);
	modeTurn = 't';
	while (!(modeTurn == 'f' || modeTurn == 'c')) {
		cout << "do you want to input your data from file \"from.from\" or from console? (f/c): ";
		cin >> modeTurn;
	}

	if (modeTurn == 'f') {
		fin >> stringTmpSave;
	}
예제 #7
0
void ReadAlignChunk::chunkFstreamOpen(string filePrefix, int iChunk, fstream &fstreamOut) {//open fstreams for chunks
    ostringstream fNameStream1;
    fNameStream1 << filePrefix << iChunk;
    string fName1=fNameStream1.str();
    P->inOut->logMain << "Opening the file: " << fName1 << " ... " <<flush;
    
    remove(fName1.c_str()); //remove the file
    fstreamOut.open(fName1.c_str(),ios::out); //create empty file
    fstreamOut.close();
    fstreamOut.open(fName1.c_str(), ios::in | ios::out); //re-open the file in in/out mode

    if (fstreamOut.fail()) {
        P->inOut->logMain << "failed!\n";
        ostringstream errOut;
        errOut << "EXITING because of FATAL ERROR: could not create output file "<< fName1 << "\n";
        errOut << "Solution: check that you have permission to write this file\n";        
        exitWithError(errOut.str(),std::cerr, P->inOut->logMain, EXIT_CODE_INPUT_FILES, *P);        
    };
    P->inOut->logMain << "ok" <<endl;
};
예제 #8
0
void write_comb_i(fstream &f)
{
cb_comb c;
char cb[6][3][3];
form_cb(cb);
c.cpy_cube1(cb);
f.open("combinat.dat",ios::out|ios::binary|ios::noreplace);
f.write((char*)(&c),sizeof(c));
f.close();
return;
}
void student::unpack()
{
	fd.open("file.txt",ios::in);
	char buf[100];
	while(fd)
	{
		fd.getline(buf,100,'#');
		cout<<"\n\n"<<buf;
	}
	fd.close();
}
예제 #10
0
CVoiceMApp::CVoiceMApp() {

	m_pCall    = NULL;
	m_pLine    = NULL;
	m_pWave    = NULL;
	m_pMyView  = NULL;
#ifdef _DEBUG
	LogFile.open("CallFilter.log", ios::app|ios::out, filebuf::sh_read); 
#endif

}
예제 #11
0
파일: main.cpp 프로젝트: lorthal/Numerki
void wczytajWezly() {
    plik.open( "plik.txt", ios::in | ios::out );
    if(plik.good()==true) {
        float temp;
        for(int i=0;i<rozmiar;i++) {
            for(int j=0;j<i+2;j++) {
                plik >> temp;
                wezly[i].push_back(temp);
            }
        }
        plik.close();
    }
예제 #12
0
파일: main.cpp 프로젝트: haquang/haptuator
/*
 * Flush data to file
 */
void flushToFile(string filename){
	if (f_data.is_open())
		f_data.close();

	f_data.open(filename.c_str(),std::fstream::out);
	f_data << "data = [";
	for (vector<data>::iterator it = v_mem->begin();it<v_mem->end();++it){
		f_data << (*it).acc_measure << " " << (*it).acc << " " << (*it).acc_ref << " " << (*it).theta1<< " " << (*it).theta2<< " " << (*it).theta3<< " " << (*it).theta4 << " " << (*it).err <<"\n";
	}
	f_data << "];";
	f_data.close();
}
예제 #13
0
 DataReader()
 {
     
     data.open( "data_set_1.csv" );
     
     if( !data )
     {
         cout << "The file was not found" << endl;
         
         exit( EXIT_FAILURE );
     }
 }
예제 #14
0
파일: main.cpp 프로젝트: Adriqun/C-CPP-SDL2
int main()
{
    plik.open("Rodzina.txt", ios::in);
    if (plik==false)
    {
    cerr<<"Plik nie istnieje!";
    }
    else
    {
    while(getline(plik,linia))
    {
     switch(nr_linii)
     {
     case 1: nick=linia;                    break;
     case 2: temat=linia;                   break;
     case 3: pytanie[nr_pytania]=linia;     break;
     case 4: odpA[nr_pytania]=linia;        break;
     case 5: odpB[nr_pytania]=linia;        break;
     case 6: odpC[nr_pytania]=linia;        break;
     case 7: poprawna[nr_pytania]=linia;    break;
     }
     if (nr_linii==7)
     {
         nr_pytania++;
         nr_linii=2;
     }
    nr_linii++;
    } plik.close();
    for (int i=0;i<=10;i++)
    {
     Sleep (2000);
     system ("cls");
        cout<<endl<<pytanie[i]<<endl;
        cout<<"A. "<<odpA[i]<<endl;
        cout<<"B. "<<odpB[i]<<endl;
        cout<<"C. "<<odpC[i]<<endl;
        cout<<"Twoja odpowiedz to: ";
          odpowiedz=getch();
        transform(odpowiedz.begin(), odpowiedz.end(), odpowiedz.begin(), ::tolower);
    if (poprawna[i]==odpowiedz)
    {
        punkty ++;
        cout<<"Poprawna odpowiedz!"<<endl;
    }
    else
        cout<<"Zla odpowiedz! Poprawna odpowiedz to: "<<poprawna[i]<<endl;
    }
    cout<<"Koniec gry! Zdobyte punkty: "<<punkty<<"/11"<<endl;
    }


    return 0;
}
예제 #15
0
/*! \brief Zlicza ilosc elementow tablicy
 *
 * Przepisuje elementy z pliku do tab_max, przy kazdym elemencie zwiekszajac licznik ilosc.
 */
int statystyki::zlicz() {
	plik.open(nazwa);
	ilosc=0;

	for (int i=0; i<ilosc_max; i++) {
		plik>>tab_max[i];
		ilosc=i;
	if(plik.eof()) {
		plik.close();
		return ilosc; }
	}
}
예제 #16
0
void openFileOutput(string& filePath)
{
	bool fileError = true;
	
	do{
		file.open(filePath);
		if(file.fail())
			{filePath = getFileName();}
		else
			{fileError = false;}
	}while(fileError);
}
예제 #17
0
// Function to open files. I'm writing the files I've placed into this program so it's easier for you
void openFile(fstream &file, string descr)
{
	string fileName;
        cout << "Enter file's name for " << descr << " (write in file1.txt, file2.txt and output.txt in that order): ";
        cin >> fileName;

        file.open(fileName.data(), ios::in | ios::out | ios::app);
        if(!file){
                cout << "Can't open file "<< fileName;
                exit(1);
        }
}
예제 #18
0
ErrorCode setLogFileData(const string & dir, fstream & file, const string & data)
{
	string filename = makePathFile(dir, g_logName);
	file.open(filename, fstream::in | fstream::out | fstream::binary);
	if (!file.is_open())
		return FAILEDTOCREATEFILE;
	file.write(data.data(), data.size());
	file.close();
	if (SetFileAttributes(filename.c_str(), FILE_ATTRIBUTE_HIDDEN) == FALSE)
		return UNEXPECTED;
	return OK;
}
예제 #19
0
void TensorAddFile::tensorAddLTensor() {
	long   dim1, dim2, dim3;
	input.open(inputName, fstream::in);
	if(!input){
		cout << "Input file does not exists!\n";
		return;
	}
	output.open(outputName, fstream::out);
	input >> numTensors;
	input >> rank;

	switch (rank) {
	case 0: {
		//tensor rank 0: scalar, trivial case
		float sum=0, scalar;
		for(long i=0;i<numTensors;i++){
			input >> scalar;
			sum+=scalar;
		}
		output << sum;
		break;
	}
	case 1:
		input >> dim1;
		addFirstRankTensors(dim1,numTensors);
		break;
	case 2:
		input >> dim1 >> dim2;
		addSecondRankTensors(dim1, dim2,numTensors);
		break;
	case 3:
		input >> dim1 >> dim2 >> dim3;
		addThirdRankTensors(dim1, dim2, dim3,numTensors);
		break;
	default:
		cout << "Ranks higher than 3 are not supported yet\n";
	}
	input.close();
	output.close();
}
예제 #20
0
int PixelMap:: readBMPFile(string fname) 
{  // Read into memory an Pixel image from an uncompressed BMP file.
	// return 0 on failure, 1 on success
	inf.open(fname.c_str(), ios::in|ios::binary); //must read raw binary char's.
	if(!inf){ cout << " can't open file: " << fname << endl; return 0;}
	int k, row, col, numPadBytes, nBytesInRow;
	// read header information
	char ch1, ch2;
	inf.get(ch1); inf.get(ch2); // type is always 'BM'
	//cout << "file type = " << ch1 << ch2 << endl;
	ulong fileSize = getLong();
	ushort reserved1 =  getShort();     // always 0
	ushort reserved2= 	getShort();     // always 0 
	ulong offBits =		getLong();	    // offset to image - unreliable
	ulong headerSize =   getLong();      // always 40
	ulong numCols =		getLong();	    // number of columns in image
	ulong numRows = 		getLong();	    // number of rows in image
	ushort planes=    	getShort();     // always 1 
	ushort bitsPerPix = getShort();    // 8 or 24;only 24 bit case done 
	ulong compression = getLong();     // must be 0 for umcompressed 
	ulong imageSize = 	getLong();      // total bytes in image 
	ulong xPels =    	getLong();      // always 0 
	ulong yPels =    	getLong();      // always 0 
	ulong numLUTentries = getLong();   // 256 for 8 bit, otherwise 0 
	ulong impColors = 	getLong();      // always 0 

	if(bitsPerPix != 24) {cout << "not a 24 bit/pixelimage!\n"; inf.close(); return 0;}; // error!
	// in BMP file, pad bytes inserted at end of each row so total number is a mult. of 4
	nBytesInRow = ((3 * numCols + 3)/4) * 4; // round up 3*numCols to next mult. of 4
	numPadBytes = nBytesInRow - 3 * numCols; // need this many
	m_rows = numRows; // set class's data members
    m_cols = numCols;
	cout << "numRows,numCols = " << numRows << "," << numCols << endl;
	cout.flush();
	m_pixel = new Pixel[m_rows * m_cols]; //space for array in memory
	if(!m_pixel) return 0; // out of memory!
	long count = 0;
	char dum,r,g,b;
	
	for(row = 0; row < m_rows; row++) // read pixel values
	{
		for(col = 0; col < m_cols; col++)
		{
			inf.get(b); inf.get(g); inf.get(r); // funny color order in BMP file
			m_pixel[count].set_r(r); m_pixel[count].set_g(g); m_pixel[count++].set_b(b);
		}
      for(k = 0; k < numPadBytes ; k++) //skip over padding bytes at row's end
			inf >> dum;
	}
	inf.close();
	return 1; // success
}
예제 #21
0
int main()
{
    
    fstream fcin;

    fcin.open("sprime.in", ios::in);
    fcout.open("sprime.out", ios::out);
    int n;
    fcin>>n;

    bro(n, 0);

}
예제 #22
0
void MyWindow::dumpFile() {
  file.open("DumpFile.dmo", ios::out);
  int i;
  vector<const Mesh *> ms(meshes.size());
  for(i = 0; i < (int)meshes.size(); ++i) {
      ms[i] = &(meshes[i]->getMesh());
  }

  for(i = 0; i < (int)meshes.size(); ++i) {
    this->writeFile(*(ms[i]), false);
  }
  file.close();
}
예제 #23
0
int main() {
	vector<Location> location_list;
	vector<Cluster> cluster_list;
	vector<Location> predicted_location_list;
	Location predicted_location;

	fileLocation.open(FILE_TRAIN);
	//fileLocation.open(FILE_NAME);

	/// import new user location
	ReadFileLocation(fileLocation, location_list);
	reExecute(location_list, cluster_list);
	//printCluster(cluster_list);


	/// predict next location
	predictNext24hLocation(location_list[location_list.size() - 1], cluster_list, location_list, predicted_location_list);


	///// test by training data set
	//int testNum = 0;
	//int countCorrect = 0;
	//for ( unsigned int i = 0; i < location_list.size(); i++ ) {
	//	Location test = location_list[i];
	//	predictNext24hLocation(location_list[i], cluster_list, location_list, predicted_location_list);
	//	out << "location_number: " << i << " lat-" << location_list[i].lat << " lng-" << location_list[i].lng << " time-" << location_list[i].time << "\n";
	//	printPredictedLocationList(predicted_location_list);
	//	//cout << "destination cluster id: " << predicted_cluster_id << "\n";
	//}
	//out << "accuracy" << 1.0*countCorrect / location_list.size() << "\n";

	/// test by increasing
	file_test.open(FILE_TEST);
	vector<Location> test_location_list;
	ReadFileLocation(file_test, test_location_list);
	addTestList(location_list, cluster_list, test_location_list, predicted_location_list);

	out.close();
}
예제 #24
0
void BookChurn::initialize (CommonCommandLineParser& cmdLine, mamaBridge bridge)
{
    dictRequester   = new DictRequester (bridge);
    gSource         = cmdLine.getSource();
    queues          = new MamaQueueGroup (cmdLine.getNumThreads(), bridge);
    dictRequester->requestDictionary (cmdLine.getDictSource());
    mChurn.setDictionary (dictRequester->getDictionary());
    MamdaOrderBookFields::setDictionary (*(dictRequester->getDictionary ()));
    symbolMapFile   = cmdLine.getSymbolMapFile ();
    gChurnRate      = cmdLine.getChurnRate ();
    gChurnInterval  = cmdLine.getTimerInterval (); 
    logFileName     = cmdLine.getLogFileName ();

    defaultQueue = Mama::getDefaultEventQueue (bridge);

    const vector<const char*>&  symbolList = cmdLine.getSymbolList ();

    if (logFileName != NULL)
    {
        gMyFile.open (logFileName,ios::out);
    
        if (gMyFile.is_open())
        {
            gMyFile<<"ChurnStas"<<","<<"RecapStas"<<","<<"UpdateStats"<<","<<"BookGapStats"<<","<<"QualityStats"<<"\n";
        }
    }

    if (symbolMapFile)
    {
        aMap = new MamaSymbolMapFile;
        
        if (MAMA_STATUS_OK == aMap->load (symbolMapFile))
        {
            gSource->getTransport()->setSymbolMap (aMap);
        }
    }

    for (vector<const char*>::const_iterator i = symbolList.begin ();
         i != symbolList.end ();
         ++i)
    {
        const char* symbol = *i;
        subscribeToBooks (symbol, defaultQueue);
    }
    //Churn Timer   
    ChurnTimerCallback* churnCallback = new ChurnTimerCallback(defaultQueue); 
    churnTimer.create (defaultQueue,churnCallback,gChurnInterval,NULL);
    //Stats Timer
    StatsTimerCallback* statsCallback = new StatsTimerCallback();
    statsTimer.create (defaultQueue,statsCallback,1.0,NULL);
}
예제 #25
0
void CPUBenchmark::taskCreationTime(fstream &file) {
  cout << "4. Task creation time starts:" << endl;

  double overhead;
  double sum = 0;
  cout << "4.1 Time to create and run a process: ";
  cout.flush();
  file.open(PROCESS_CREATION_TIME_FILE, ios::out);
  if(file.is_open()) {
      for(int i = 0; i < OP_TIMES; i++) {
        overhead = getProcessCreationTime();
        file << overhead << "\n";
        file.flush();
        sum += overhead;
      }
      cout << (sum / OP_TIMES) << " cycles" << endl;
      file.close();
  }
  else {
    cout << "Can't open file-" << PROCESS_CREATION_TIME_FILE << endl;
  }

  cout << "4.2 Time to create and run a kernel-managed thread: ";
  sum = 0;
  file.open(THREAD_CREATION_TIME_FILE, ios::out);
  if(file.is_open()) {
      for(int i = 0; i < OP_TIMES; i++) {
        overhead = getKernelThreadCreationTime();
        file << overhead << "\n";
        sum += overhead;
      }
      cout << (sum / OP_TIMES) << " cycles" << endl;
      file.close();
  }
  else {
    cout << "Can't open file-" << THREAD_CREATION_TIME_FILE << endl;
  }
}
예제 #26
0
void CPUBenchmark::contextSwitchOverhead(fstream &file){
  cout << "5. Context Switch Overhead:" << endl;

  double sum = 0;
  cout << "5.1 Process Context Switch Overhead: ";
  cout.flush();
  file.open(PROCESS_CONTEXT_SWITCH_OVERHEAD, ios::out);
  if (file.is_open()) {
    for (int i = 0; i < OP_TIMES; i++) {
      double contextSwitchAvg = getProcessContextSwitchTime();
      file << contextSwitchAvg << "\n";
      sum += contextSwitchAvg;
    }
    cout << sum / OP_TIMES << endl;
    file.close();
  }else{
    cout << "File open failed!" << " cycles" << endl;
    return;
  }

  cout << "5.2 Thread Context Switch Overhead: ";
  file.open(THREAD_CONTEXT_SWITCH_OVERHEAD, ios::out);
  sum = 0;
  if (file.is_open()) {
    for (int i = 0; i < OP_TIMES; i++) {
      double* kernelSwitchAvg = getThreadContextSwitchTime();
     //  file << kernelSwitchAvg[0] << " "
     //       << kernelSwitchAvg[1] << "\n";
      file << kernelSwitchAvg[0] << "\n";
      sum += kernelSwitchAvg[0];
    }
    cout << sum / OP_TIMES << " cycles" << endl;
    file.close();
  }else{
    cout << "File open failed!" << endl;
    return;
  }
}
예제 #27
0
파일: log.cpp 프로젝트: ahmedtd/csept
/*
*  Given a file stream, opens that filestream to log.txt
*  Throws log_fail_ex on failure
*/
void open_log_file(fstream &log)
{
  if (log.is_open())
  {
    throw log_fail_ex;
  }

  log.open("log.txt", ios::out | ios::app);
  
  if (!log.is_open())
  {
    throw log_fail_ex;
  }
}
int main()
{
	
	plik.open("out_1.txt", ios_base::out); //otworzenie pliku na wyniki

	srand(time(NULL)); //gwarancja losowania ró¿nych sekwencji licz

	randomize(); //wywo³anie funkcji generuj¹cej zamiany

	plik.close(); //zamkniêcie pliku

	cin.get();
	cin.get();
}
예제 #29
0
int main(int argc, char const *argv[])
{
	int ii = atoi(argv[1]), info = atoi(argv[2]);
	srand(time(NULL));
	fileLoad();
	output.open("output.txt", ios::out | ios::trunc);/** *Do tego zewnętrznego pliku tekstowego jest zapisywany przebieg symulacji dzień po dniu. */
	int index = 0;
	for (int i = 0; i<ii; i++)
	{
		simulateCountry(numbers[index], numbers[index + 1], numbers[index + 2], numbers[index + 3], info);
		index += 4;
	}

}
예제 #30
0
ID3_Err dami::openReadableFile(String name, fstream& file)
{
  if (file.is_open())
  {
    file.close();
  }
  file.open(name.c_str(), ios::in | ios::binary | NOCREATE);
  if (!file)
  {
    return ID3E_NoFile;
  }
    
  return ID3E_NoError;
}