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


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

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


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

示例1: ParseFiles

void ParseFiles()
{
	int offset = outfile.tellp();
	
	for(int i = 0; i < files.size(); i++)
	{
		ifstream infile(files[i].c_str(), ifstream::binary);
		int size = 0;
		
		infile.seekg(0, ios::end);
		size = infile.tellg();
		infile.seekg(0, ios::beg);
		
		if(size == 0)
			continue;
		
		cout << "[+] " << files[i] << " size[" << setw(8) << setfill('0') << size << "]" << endl;
		
		char *data = new char[size];
		infile.read(data,size);
		outfile.write(data,size);
		delete data;
		
		int curOffset = outfile.tellp();
		outfile.seekp(8*i);
		outfile.write((char*)&offset,4);
		outfile.write((char*)&size,4);
		outfile.seekp(curOffset);
		
		offset += size;
		infile.close();
	}
}
开发者ID:polaris-,项目名称:nanashi_no_game,代码行数:33,代码来源:createtra.cpp

示例2: writeFile

static bool writeFile(const wstring &res, ofstream &fs, bkplong pos)
{
	static unsigned short magic = 0xFEFF;
	//write in Unicode16-LE
	if (!fs.good())
		return false;
	if (pos >= 0)
		fs.seekp(pos, ios_base::beg);
	else
		fs.seekp(pos + 1, ios_base::end);
	fs.write((const char *)&magic, 2);
	u16string result;
	bkplong s = res.size();
	bkplong s2 = s * sizeof(wchar_t) / sizeof(char16_t);
	result.resize(s2);
#ifdef HAVE_CODECVT
	auto& f = use_facet<codecvt<wchar_t, char16_t, mbstate_t>>(locale());
	mbstate_t mb = mbstate_t();
	char16_t* from_next;
	const wchar_t* to_next;
	f.out(mb, &res[0], &res[s], to_next, &result[0], &result[s2], from_next);
#else
	ucs4toutf16((uint16_t *)&result[0], (uint32_t *)&res[0], s);
#endif
	fs.write((const char *)result.c_str(), 2 * result.length());
	return true;
}
开发者ID:Icemic,项目名称:BKOven,代码行数:27,代码来源:utils.cpp

示例3: CreateFile

void CQualLL::CreateFile(ofstream &fp){
	char *block;
  ifstream fileTemp;
	size_t IndexPos = 0, pos_input = 0, end_input = 0, aux = 0, inpos = 1;
	if(CQual.length() != 0){
		CQual = GZcompressString(CQual);
		SaveValue(fileQual, CQual.length());
		SaveValue(fileQual, (char *)CQual.c_str(), CQual.length());
		CQual = "";
	}
	fileQual.close();
	SaveValue(fp, LOSSLESS);
	cds_word Variables[2];
	Variables[0] = IndexRate;
	Variables[1] = numberOfLines;
	SaveValue(fp, Variables, 2);
	buffer = init_buffer();
	buffer_use = 0;
	if(IndexRate > 0){//this will be overwrite at the end
		IndexPos = fp.tellp();
		IndexLine = new cds_word[1 + (numberOfLines + IndexRate - 1)/IndexRate];
		for(cds_word w = 0; w < (1 + (numberOfLines + IndexRate - 1)/IndexRate); w++)
			IndexLine[w] = 0;
		SaveValue(fp, IndexLine, 1 + ((numberOfLines + IndexRate - 1)/IndexRate));
	}
	init_qual = fp.tellp();
	init_qual += 2 * sizeof(size_t);
	SaveValue(fp, init_qual);
	SaveValue(fp, end_qual);

	fileTemp.open(tmp_name.c_str());
	pos_input = fileTemp.tellg();
	fileTemp.seekg(0, std::ifstream::end);
	end_input = fileTemp.tellg();
	fileTemp.seekg(pos_input);
	if(IndexRate > 0)	
		IndexLine[0] = fp.tellp();
	while(pos_input < end_input){
		aux = LoadValue<size_t>(fileTemp);
		block = LoadValue<char>(fileTemp, aux);
		pos_input += aux + sizeof(size_t);
		SaveValue(fp, block, aux);
		if(IndexRate > 0){
			IndexLine[inpos] = fp.tellp();
			inpos ++;
		}
		delete [] block;
	}
	fileTemp.close();
	end_qual = fp.tellp();
	fp.seekp(IndexPos);
	if(IndexRate > 0)
		SaveValue(fp, IndexLine, (1 + (numberOfLines + IndexRate - 1)/IndexRate));
	delete [] buffer;
	fp.seekp(init_qual - sizeof(size_t));
	SaveValue(fp, end_qual);
	fp.seekp(end_qual);
	remove(tmp_name.c_str());
}
开发者ID:rcanovas,项目名称:libCSAM,代码行数:59,代码来源:CQualLL.cpp

示例4: getFileSize

size_t dami::getFileSize(ofstream& file)
{
  size_t size = 0;
  if (file.is_open())
  {
    streamoff curpos = file.tellp();
    file.seekp(0, ios::end);
    size = file.tellp();
    file.seekp(curpos);
  }
  return size;
}
开发者ID:rusingineer,项目名称:eMule-scarangel,代码行数:12,代码来源:utils.cpp

示例5: distance

	void distance(){

		if(System::file().doesExist(_outputDir + "/mat_presenceAbsence_jaccard.bin")){
			_distanceMatrixJaccard.open((_outputDir + "/mat_presenceAbsence_jaccard.bin").c_str(), ios::binary | ios::in);
			_distanceMatrixBrayCurtis.open((_outputDir + "/mat_abundance_braycurtis.bin").c_str(), ios::binary | ios::in);
		}
		else{
			_distanceMatrixJaccard.open((_outputDir + "/mat_presenceAbsence_jaccard.bin").c_str(), ios::binary);
			_distanceMatrixBrayCurtis.open((_outputDir + "/mat_abundance_braycurtis.bin").c_str(), ios::binary);
		}

		bool isSymmetrical = false;
		if(_inputFilename1 == _inputFilename2 && _start_i == _start_j){
			computeDistanceSymetrical();
			isSymmetrical = true;
		}
		else{
			computeDistanceRectangle();
		}


		for(size_t i=0; i<_threads.size(); i++){
			_threads[i]->join();
			delete _threads[i];
			//cout << i << endl;
		}

		_progress->finish();

		//Fill diagonal with 0

		if(isSymmetrical){
			for(size_t i=_start_i; i<_start_i+_n_i; i++){
				size_t j=i;
				u_int64_t pos = i*_nbDataset1*sizeof(DistanceValueType) + (j*sizeof(DistanceValueType));
				_distanceMatrixJaccard.seekp(pos);
				_distanceMatrixBrayCurtis.seekp(pos);
				DistanceValueType nullDist = 0;
				_distanceMatrixJaccard.write((const char*)&nullDist, sizeof(nullDist));
				_distanceMatrixBrayCurtis.write((const char*)&nullDist, sizeof(nullDist));
			}
		}


		_distanceMatrixJaccard.close();
		_distanceMatrixBrayCurtis.close();

		//string command = "cp " + string(_inputFilename1+".ids") + " " + _outputDir + "/matrix_infos.ids ";
		//cout << command << endl;
		//system(command.c_str());
	}
开发者ID:GATB,项目名称:simka,代码行数:51,代码来源:SimkaMinDistance.hpp

示例6: writeHeader

    /**
     * @brief writeHeader Write the header out to a file
     * @param file
     */
    void writeHeader(ofstream &file)
    {
        // Write out the header information
        file.seekp(0, ios::beg);

        file.write((char*)&this->header, sizeof(this->header));
    }
开发者ID:jacob-swanson,项目名称:school-projects,代码行数:11,代码来源:main.cpp

示例7: 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

示例8: WriteFileHeader

void Picture::WriteFileHeader(ofstream& fout)const
{
	fout.seekp(0);
	fout.write(fileHeader.fileType,2);
	fout.write((char*)&fileHeader.bfSize,4);
	fout.write((char*)&fileHeader.bfReserved1,2);
	fout.write((char*)&fileHeader.bfReserved2,2);
	fout.write((char*)&fileHeader.bfOffBits,4);
}
开发者ID:mshafer1,项目名称:ShapesToBitmap,代码行数:9,代码来源:Picture.cpp

示例9: 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

示例10: writeSample

    /**
     * @brief writeSample Write a sample out to a file
     * @param sample
     * @param file
     */
    void writeSample(short sample, ofstream &file)
    {
        // Calculate sample offset
        int sampleOffset = 44 + (this->samplesWritten * 2);

        // Seek to location of next sample and write
        file.seekp(sampleOffset);
        file.write((char*)&sample, sizeof(sample));

        // Increment number samples written
        this->samplesWritten++;
    }
开发者ID:jacob-swanson,项目名称:school-projects,代码行数:17,代码来源:main.cpp

示例11: onMessage

    // Called from the consumer since this class is a registered MessageListener.
    virtual void onMessage( const Message* message ) {
        try
        {
            const TextMessage* textMessage =
                dynamic_cast< const TextMessage* >( message );
            string text = "";

            if( textMessage != NULL ) {
                text = textMessage->getText();
                const Topic* destination = dynamic_cast<const Topic*>(textMessage->getCMSDestination());
                destination->getTopicName();

                // Do something with the text, like:
                printf("Number of received message is %d\n",numMessage);
				printf( "Message Received, messageType: %s, message content: %s\n",destination->getTopicName().c_str(), text.c_str() );
				
				// output message into log file

				//open the log file
oFile.open("log_PAS.txt",ios::app);

	//move point to the end of the file, append information at the  end of the log file
	oFile.seekp(0,ios::end);

vector<string> logStr3;
logStr3.push_back("\nMessage Received, messageType: ");
logStr3.push_back(destination->getTopicName().c_str());
logStr3.push_back("\n message content: ");
logStr3.push_back(text.c_str());
logStr3.push_back("\n Number of received Message are : ");
std::stringstream strNum;
strNum << numMessage;
logStr3.push_back(strNum.str());
	copy(logStr3.begin(),logStr3.end(),ostream_iterator<string>(oFile));
//close the log file
	oFile.close();
	numMessage++;



            } else {
                // Log the error
                cerr << "Received a non-text message" << endl;
            }

        } catch (CMSException& e) {
            // Log the error
            cerr << "Opps! B exception happened: " << e.getMessage() << endl;
        }
    }
开发者ID:Erkan-Yilmaz,项目名称:AutomationTestFramework,代码行数:51,代码来源:main.cpp

示例12: WriteSector

void MakeImage::WriteSector(ofstream &stream, int sectorNum, char *data) {

    int writePos = sectorNum * SECTOR_SIZE;

    // get end of file pos
    stream.seekp(0, ios::end);
    int endPos = stream.tellp();

    if(endPos <= writePos) {

        do {
            stream.put(0);
            endPos = stream.tellp();
        }
        while(endPos <= writePos);
    }


    stream.seekp(writePos);
    stream.seekp(0, ios_base::cur);

    stream.write(data, SECTOR_SIZE);

}
开发者ID:mrfalcone,项目名称:TwistOS,代码行数:24,代码来源:MakeImage.cpp

示例13: ihexcallback

void ihexcallback(const uint8_t *ptr, size_t offset, size_t len)
{
    //printf("callback: offset %#zx, len %zu\n", offset, len);

    // apply the file offset
    if (fileoffset > offset) {
        fprintf(stderr, "error: offset in hex file out of range of file offset, o %#zx to %#zx\n", offset, fileoffset);
        exit(1);
    }

    offset -= fileoffset;

    out.seekp(offset);
    out.write((const char *)ptr, len);
}
开发者ID:travisg,项目名称:libihex,代码行数:15,代码来源:ihextobin.cpp

示例14: WriteInfoHeader

void Picture::WriteInfoHeader(ofstream& fout) const
{
	fout.seekp(14);
	fout.write((char*)&infoHeader.biSize,4);
	fout.write((char*)&infoHeader.biWidth,4);
	fout.write((char*)&infoHeader.biHeight,4);
	fout.write((char*)&infoHeader.biPlanes,2);
	fout.write((char*)&infoHeader.biBitCount,2);
	fout.write((char*)&infoHeader.biCompression,4);
	fout.write((char*)&infoHeader.biSizeImage,4);
	fout.write((char*)&infoHeader.biXPixelsPerMeter,4);
	fout.write((char*)&infoHeader.biYPixelsPerMeter,4);
	fout.write((char*)&infoHeader.biClrUsed,4);
	fout.write((char*)&infoHeader.biClrImportant,4);
}
开发者ID:mshafer1,项目名称:ShapesToBitmap,代码行数:15,代码来源:Picture.cpp

示例15: jumpToLine

//jump to line n in functions
bool MapBuilder::jumpToLine(int n, ifstream &lookFile, ofstream &putFile){ 
   bool newLine = false;   
   
   lookFile.seekg(ios_base::beg); //set cursor to the beginning
   int counter = 0;
   while((n < counter) && (!file.eof())){ //search for n new lines
      if(findsNLChar(lookFile)){ //if you find a new line
         counter++;         //count that
      }
   }
   
   if(!lookFile.eof()){ //if we got to the end before making n lines
      return false; //we never made it
   }
   
   putFile.seekp(lookFile.tellg()); //put the putting pointer to where looking pointer is
   return true;     //successfully got to line n
}
开发者ID:julianborrey,项目名称:Angelica,代码行数:19,代码来源:netBuilder.cpp


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