当前位置: 首页>>代码示例>>C++>>正文


C++ ofstream::clear方法代码示例

本文整理汇总了C++中ofstream::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::clear方法的具体用法?C++ ofstream::clear怎么用?C++ ofstream::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ofstream的用法示例。


在下文中一共展示了ofstream::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: figure

void figure()
{
	int i;

	/*fout.open("E:\\data\\KSP\\Fat-tree\\bn-B\\4.txt");
	fout.clear();
	fout.close();
	fout.open("E:\\data\\KSP\\Fat-tree\\bw-B\\1.txt");
	fout.clear();
	fout.close();*/
	fout.open("E:\\data\\KSP\\Fat-tree\\suc-B\\1.txt");
	fout.clear();
	fout.close();

	/*fout.open("E:\\data\\KSP\\Fat-tree\\bn-B\\4.txt",ios::app);
	for(i=1;i<=cycle;i++)
		fout<<bn_array[i]<<" ";
	fout.close();

	fout.open("E:\\data\\KSP\\Fat-tree\\bw-B\\1.txt",ios::app);
	for(i=1;i<=cycle;i++) 
		fout<<bw_array[i]<<" ";
	fout.close();*/

	fout.open("E:\\data\\KSP\\Fat-tree\\suc-B\\1.txt",ios::app);
	for(i=1;i<=cycle;i++)
		fout<<double(suc_array[i])/(times-1)<<" "; //times会增长到6
	fout.close();
}
开发者ID:luchukun,项目名称:vne,代码行数:29,代码来源:FatTree.cpp

示例2: Towers_sm

int Towers_sm(int disks, int arr1[], int arr2[], int count, bool &ppart, ofstream &fout, ofstream &outfile)
{
	int split;
   	int split_res;
   	int remaining;
 	int remaining_res;
 	int result;
 	int diskssofar;
 	int smallest_so_far;

	for(diskssofar = 1; diskssofar < count; diskssofar++)
	{
		arr2[diskssofar - 1] = 2*(diskssofar) - 1;
		ppart = true;
	}
		
 	if(diskssofar >= count)
 	{
 		for(int a = diskssofar; a <= disks; a++)
		{
			//Resetting "smallest_so_far"
			smallest_so_far = INT_MAX;

			for(split = 1; split < diskssofar; split++)
			{
				remaining = diskssofar - split;
				split_res = arr2[split - 1];

				remaining_res = arr1[remaining - 1];
				result = 2*(split_res) + remaining_res;

				//Only update "smallest_so_far" if "result" is lower
				if(result <= smallest_so_far)
					smallest_so_far = result;
			}
			//Setting the used array to "smallest_so_far"
			arr1[a-1] = smallest_so_far;
			ppart = false;
		}
 	}

 	cout << "The array is: ";
	outfile << "The array is: ";
 	for (int g = 0; g < disks; g++)
 	{
		cout << arr2[g] << " ";
		fout << arr2[g] << " ";
		outfile << arr2[g] << " ";
	}
	cout << endl;
	outfile << endl;

	//Setting the writting stream cursor back to the beginning
	fout.clear();
	fout.seekp(0);

	return arr2[disks - 1];
}
开发者ID:TFullagar,项目名称:Towers,代码行数:58,代码来源:Towers4.1.cpp

示例3: fileopenbinary

void a::fileopenbinary(ofstream &out, const string &filename, Error &error) {
  out.clear();
  out.open(filename.c_str(),ios::binary);
  if (!out) {
    error.addwarning(2,15,"Misc",
                     "Could not open "+string(filename)+" for output!");
    error.writewarnings();
  }
}
开发者ID:behollis,项目名称:muViewBranch,代码行数:9,代码来源:misc.cpp

示例4: fileopen

void a::fileopen(ofstream &out, const char *filename, Error &error) {
  out.clear();
  out.open(filename);
  if (!out) {
    error.addwarning(2,15,"Misc",
                     "Could not open "+string(filename)+" for output!");
    error.writewarnings();
  }
}
开发者ID:behollis,项目名称:muViewBranch,代码行数:9,代码来源:misc.cpp

示例5: chunkFstreamCat

void ReadAlignChunk::chunkFstreamCat (fstream &chunkOut, ofstream &allOut, bool mutexFlag, pthread_mutex_t &mutexVal){
    chunkOut.flush();
    chunkOut.seekg(0,ios::beg);
    if (mutexFlag) pthread_mutex_lock(&mutexVal);
    allOut << chunkOut.rdbuf();
    allOut.clear();
    if (mutexFlag) pthread_mutex_unlock(&mutexVal);
    chunkOut.clear();
    chunkOut.seekp(0,ios::beg); //set put pointer at the beginning
};
开发者ID:gvessere,项目名称:STAR,代码行数:10,代码来源:ReadAlignChunk.cpp

示例6: promptUserForFile

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: ";
   }
}
开发者ID:zmukwa,项目名称:stanford-whittier-cpplib,代码行数:12,代码来源:filelib.cpp

示例7: figure

void figure()
{
	int i;

	fout.open("E:\\data\\N-bn\\bottleneck3.txt");
	fout.clear();
	fout.close();
	fout.open("E:\\data\\N-suc\\success3.txt");
	fout.clear();
	fout.close();

	fout.open("E:\\data\\N-bn\\bottleneck3.txt",ios::app);
	for(i=0;i<cycle;i++) //(N=1;N<=20;N++)
		fout<<bn[i]<<" ";
	fout.close();

	fout.open("E:\\data\\N-suc\\success3.txt",ios::app);
	for(i=0;i<cycle;i++) //(N=1;N<=20;N++)
		fout<<double(success[i])/(times-1)<<" "; //times-1是因为for循环多加了1
	fout.close();
}
开发者ID:luchukun,项目名称:vne,代码行数:21,代码来源:exhaustive.cpp

示例8: setup_debug

void setup_debug(int level, const string &filename, const string& prefix)
{
    string fname = filename;
    debug_level = level;
    logfile_prefix = prefix;
    logfile_filename = filename;

    if ( logfile_file.is_open() )
        logfile_file.close();
    ostream *output = 0;
    if ( filename.length() ) {
	logfile_file.clear();
        logfile_file.open( filename.c_str(), fstream::out | fstream::app );
#ifdef __linux__
        if (fname[0] != '/') {
            char buf[256];
            if (getcwd(buf, sizeof(buf))) {
                fname.insert(0, "/");
                fname.insert(0, buf);
            }
        }
        setenv("SEGFAULT_OUTPUT_NAME", fname.c_str(), false);
#endif
        output = &logfile_file;
    } else
        output = &cerr;

#ifdef __linux__
    (void) dlopen("libSegFault.so", RTLD_NOW | RTLD_LOCAL);
#endif

    if ( debug_level & Debug )
        logfile_trace = output;
    else
        logfile_trace = &logfile_null;

    if ( debug_level & Info )
        logfile_info = output;
    else
        logfile_info = &logfile_null;

    if ( debug_level & Warning )
        logfile_warning = output;
    else
        logfile_warning = &logfile_null;

    if ( debug_level & Error )
        logfile_error = output;
    else
        logfile_error = &logfile_null;

    signal( SIGHUP, reset_debug );
}
开发者ID:CSRedRat,项目名称:icecream,代码行数:53,代码来源:logging.cpp

示例9: main

int main(int argc,char *argv[])
{
    string name,oname;
    int i;

    //char ts1[16] = "0.trace";
    //char ts2[12] = "0.symbol";
    //char ts3[10] = "1";


    if (argc != 4)
    {
        cout<<"Usage: trace2symbol inputfile outputfile $n\n"<<endl;
        return 0;
    }

    name.assign(argv[1]);
    //name.assign(ts1);
    oname.assign(argv[2]);
    //oname.assign(ts2);
    for (i=0; i<atoi(argv[3]); i++)
        //for (i=0;i<atoi(ts3);i++)
    {
        fin.open(name.c_str());

        if (fin.fail())
        {
            cout<<"Bad file name!\n"<<endl;
            return 0;
        }

        fout.open(oname.c_str());

        cout<<"Trace2Symbol(V1.0) "<<endl;

        cout << "Dealing with " << name << "...";

        work();

        fin.close();
        fout.close();
        fin.clear();
        fout.clear();

        cout << "Done." << endl;
        name=nextName(name);
        oname=nextName(oname);
    }
    return 0;
}
开发者ID:HDFGroup,项目名称:Replayer,代码行数:50,代码来源:trace2symbol.cpp

示例10: openFile

bool openFile( const string fname, ofstream &fobj )
   {
   // vars 
   bool success = false;

   // clear and open
   fobj.clear();
   fobj.open(fname.c_str());

   // check for file opening success
   if( fobj.good() )
     {
     success = true;
     }   

   // return success state
   return success;
   }
开发者ID:T-R0D,项目名称:Past-Courses,代码行数:18,代码来源:Ttools.cpp

示例11: modifyContFile

//Modify file content function
bool modelA::modifyContFile(ofstream mdfos,unsigned int startPos,unsigned int endPos,string newContent)
{
	if(endPos<startPos)
		return false;
	else
	{
		//Move ofstream pointer to end position 
		mdfos.seekp(endPos,ios_base::beg);
		//Delete old content
		for(int i=0;i<int(endPos-startPos);i++)
			mdfos.put(char(8));
		//Write new content
		mdfos<<newContent<<flush;
		//Exit and go to begin
		mdfos.clear();
		mdfos.seekp(0,ios_base::beg);
	}

	return true;
}
开发者ID:lazyrohan,项目名称:Asha,代码行数:21,代码来源:hModelGloble.cpp

示例12: Cls_OnInitDialog

BOOL CMultithreadDlg::Cls_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) 
{
	hList = GetDlgItem(hwnd, IDC_LIST1);
	InitializeCriticalSection(&our_section);

	sec_time = clock(); // начальное время
	HANDLE th1 = CreateThread(NULL, 0, Thread3, (LPVOID)0, 0, NULL);
	HANDLE th2 = CreateThread(NULL, 0, Thread4, (LPVOID)1, 0, NULL);
	HANDLE th3 = CreateThread(NULL, 0, Thread_file, (LPVOID)1, 0, NULL);

	WaitForSingleObject(th1, INFINITE);
	WaitForSingleObject(th2, INFINITE);
	WaitForSingleObject(th3, INFINITE);

	unsigned int end_time_2 = clock(); // конечное время
	sec_time = end_time_2 - sec_time; // искомое время

	SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(to_wstring(sec_time).c_str()));

	sec_time = clock(); // начальное время
	fout_2.clear();
	Thread5(0);

	end_time_2 = clock(); // конечное время
	sec_time = end_time_2 - sec_time; // искомое время

	SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(to_wstring(sec_time).c_str()));
	fout_3.close();
	//sec_time = clock(); // начальное время
	//HANDLE th3 = CreateThread(NULL, 0, Thread5, (LPVOID)0, 0, NULL);

	//WaitForSingleObject(th3, INFINITE);

	//end_time_2 = clock(); // конечное время
	//sec_time = end_time_2 - sec_time; // искомое время

	//SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(to_wstring(sec_time).c_str()));
	//CreateThread(NULL, 0, Thread_main, (LPVOID)2, 0, NULL);
	return TRUE;
}
开发者ID:Saroko-dnd,项目名称:My_DZ,代码行数:40,代码来源:MultithreadDlg.cpp

示例13: Log

  Log() {
    n = 0;
    done = false;

    output.open(LOG_FILE);
    if (!output.is_open()) {
      output.copyfmt(cout);
      output.clear(cout.rdstate());
      output.basic_ios<char>::rdbuf(cout.rdbuf());
    }

    logStartTime = chrono::high_resolution_clock::now();
    t = thread([&]() {

      Report report;
      while (!done) {
        for (int i = 0; i < NUMBER_OF_QUEUES; ++i)
          while (queue[i].pop(report))  // XXX change to if to avoid starvation?
            priority.push(report);

        double now = chrono::duration_cast<chrono::duration<double>>(
            chrono::high_resolution_clock::now() - logStartTime).count();
        while ((!priority.empty()) && ((now - priority.top().time) > 0.5)) {
          output << priority.top().text << endl;
          priority.pop();
        }

        usleep(WAIT_MICROSECONDS);
      }

      for (int i = 0; i < NUMBER_OF_QUEUES; ++i)
        while (queue[i].pop(report))
          priority.push(report);

      while (!priority.empty()) {
        output << priority.top().text << endl;
        priority.pop();
      }
    });
  }
开发者ID:mantaraya36,项目名称:cuttlebone,代码行数:40,代码来源:Log.hpp

示例14: main

int main(int argc,char *argv[])
{
  string nameIn;

  if (argc != 4) {
    cout << "Usage: combine inputfile outputfile $n" << endl << endl;
    return 0;
  }

  nameIn.assign(argv[1]);

  for (int i=0;i<atoi(argv[3]);i++) {
    input_is.open(nameIn.c_str());

    if (input_is.fail()) {
      cout << "Bad file name: [" << nameIn << "]!" << endl << endl;
      return 0;
    }

    cout << "Combine(V2.0)" << endl;
    cout << "Reading " << nameIn << "...";

    readfile();

    input_is.close();
    input_is.clear();

    cout << "Done." << endl;
    nameIn=nextName(nameIn);
  }

  res_os.open(argv[2]);
  work();

  res_os.close();
  res_os.clear();

  return 0;
}
开发者ID:HDFGroup,项目名称:Replayer,代码行数:39,代码来源:combine.cpp

示例15: main

int main(int argc, char *argv[]) {
	string inputfile_name;
	string outputfile_name;

	if (argc != 4) {
		cout << "Usage: combine inputfile outputfile $n\n" << endl;
		return 0;
	}

	inputfile_name.assign(argv[1]);
	outputfile_name.assign(argv[2]);

	fin.open(argv[1]);
	fout.open(argv[2]);
	num_procs = boost::lexical_cast<int>(argv[3]);

	if (fin.fail()) {
		cout << "Bad file name: [" << inputfile_name << "]!\n" << endl;
		return 0;
	}

	fout << preamble();

	populate_func_map();

	work();

	fin.close();
	fin.clear();

	fout << postamble();


	fout.close();
	fout.clear();

	return 0;
}
开发者ID:HDFGroup,项目名称:Replayer,代码行数:38,代码来源:replayer.cpp


注:本文中的ofstream::clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。