本文整理汇总了C++中std::ofstream::seekp方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::seekp方法的具体用法?C++ ofstream::seekp怎么用?C++ ofstream::seekp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ofstream
的用法示例。
在下文中一共展示了ofstream::seekp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_resultes_into_the_file
//Function that writes the line with name age sex and time taken by the player into the file puzzle_NxNyyy
void write_resultes_into_the_file(std::ofstream& myfile, string time){
int ii = 0;
vector<string> vec = Tokenize(time);
int here = myfile.tellp();
myfile << " ";
for (std::vector<std::string>::size_type a = 0; a < vec.size(); ++a){
switch (ii)
{
case 0:
myfile.seekp ((here + 4) );
myfile << vec.at(a);
break;
case 1:
myfile.seekp ((here + 25 ));
myfile << vec.at(a);
break;
case 2:
myfile.seekp ((here + 29 ));
myfile << vec.at(a);
break;
case 3:
myfile.seekp ((here + 31 ));
myfile << vec.at(a);
break;
}
ii++;
}
}
示例2: writeHeader
void BackgroundRemovedImage::writeHeader(std::ofstream& os) {
HeaderInfoT hi;
hi.headersize = headerSizeInBytes;
hi.idcode = idCode();
//fill in header with 0s
std::ofstream::pos_type cur_loc = os.tellp();
char zero[headerSizeInBytes] = {0};
os.write(zero, headerSizeInBytes);
std::ofstream::pos_type end_loc = os.tellp();
//return to the beginning of the header and write data
os.seekp(cur_loc);
if (differencesFromBackground.empty()) {
hi.depth = 0;
hi.nchannels = 0;
hi.numims = 0;
} else {
hi.depth = differencesFromBackground.front().second->depth;
hi.nchannels = differencesFromBackground.front().second->nChannels;
hi.numims = differencesFromBackground.size();
}
os.write((char *) &hi, sizeof(hi));
if (metadata != NULL) {
metadata->toDisk(os);
}
os.seekp(end_loc);
}
示例3: fileSize
unsigned int fileSize(std::ofstream& file)
{
unsigned int oldpos = file.tellp();
file.seekp(0, std::ios::end);
unsigned int filesize = file.tellp();
file.seekp(oldpos, std::ios::beg);
return filesize;
}
示例4: UpdateNextDataSetOffset
void DataSetHeaderWriter::UpdateNextDataSetOffset(std::ofstream &os, u_int32_t pos) const
{
if(nextDataSetPos > 0)
{
os.seekp(nextDataSetPos, std::ios::beg);
FileOutput::WriteUInt32(os, pos);
os.seekp(pos, std::ios::beg);
}
}
示例5:
std::streamoff
fileSize(std::ofstream& file)
{
std::streamoff curr = file.tellp();
file.seekp(0, std::ios::end);
std::streamoff size = file.tellp();
file.seekp(0, std::ios::beg);
size -= file.tellp();
file.seekp(curr, std::ios::beg);
return size;
}
示例6: sizeof
ELFIO_Err
ELFOSection::Save( std::ofstream& f, std::streampos posHeader,
std::streampos posData )
{
if ( 0 != GetIndex() && SHT_NOBITS != GetType() ) {
m_sh.sh_offset = Convert32Off2Host( posData, m_pIELFO->GetEncoding() );
}
f.seekp( posHeader );
f.write( reinterpret_cast<const char*>( &m_sh ), sizeof( Elf32_Shdr ) );
if ( SHT_NOBITS != GetType() ) {
f.seekp( posData );
f.write( GetData(), GetSize() );
}
return ERR_ELFIO_NO_ERROR;
}
示例7: save
bool
save( std::ofstream& stream ) const
{
stream.seekp( 0 );
stream.write( reinterpret_cast<const char*>( &header ), sizeof( header ) );
return stream.good();
}
示例8: serialise_aux
unsigned int CompactTrie::serialise_aux( std::ofstream& file, const CompactTrieNode* node, unsigned int current_offset )
{
serialise_children_list( file, node->children_ );
unsigned int children_offset = current_offset;
current_offset += calculate_list_size( node->children_ ) * COMPACT_TRIE_NODE_SIZE;
CompactTrieNodeList* children = node->children_;
while ( children != nullptr )
{
file.seekp( children_offset + COMPACT_TRIE_VALUE_SIZE + COMPACT_TRIE_FREQUENCY_SIZE, std::ios::beg );
write_binary_unsigned_int( file, current_offset, COMPACT_TRIE_CHILDREN_OFFSET_SIZE );
file.seekp( current_offset, std::ios::beg );
current_offset = serialise_aux( file, children->node_, current_offset );
children_offset += COMPACT_TRIE_NODE_SIZE;
children = children->next_;
}
return current_offset;
}
示例9: reset
virtual void reset() {
DVLOG(5) << "resetting histogram";
if (!log_initialized) {
log_initialized = true;
char * jobid = getenv("SLURM_JOB_ID");
char fname[256]; sprintf(fname, "histogram.%s/%s.%d.out", jobid, name, mycore());
log.open(fname, std::ios::out | std::ios_base::binary);
DVLOG(5) << "opened " << fname;
}
if (log_initialized) {
log.clear();
log.seekp(0, std::ios::beg);
}
value_ = nil_value;
}
示例10: processData
void ThrusterControl::processData(char* data, int size)
{
static std::ofstream gpio30("/sys/class/gpio/gpio30/value");
static std::ofstream gpio31("/sys/class/gpio/gpio31/value");
static std::ofstream gpio48("/sys/class/gpio/gpio48/value");
static std::ofstream gpio60("/sys/class/gpio/gpio60/value");
static std::ofstream pwm13("/sys/devices/ocp.3/pwm_test_P8_13.15/duty");
static std::ofstream pwm14("/sys/devices/ocp.3/pwm_test_P9_14.16/duty");
gpio30.seekp(0, gpio30.beg);
gpio31.seekp(0, gpio31.beg);
gpio48.seekp(0, gpio48.beg);
gpio60.seekp(0, gpio60.beg);
pwm13.seekp(0, pwm13.beg);
pwm14.seekp(0, pwm14.beg);
gpio30 << BinaryUtils::getBit(data[0], 0);
gpio31 << BinaryUtils::getBit(data[0], 1);
gpio48 << BinaryUtils::getBit(data[0], 2);
gpio60 << BinaryUtils::getBit(data[0], 3);
// pwm data
bool cf = BinaryUtils::getBit(data[0], 4),
zf = BinaryUtils::getBit(data[0], 5);
float xd, yd;
if(zf && !cf) // reset duty cycles (stop / 0)
{
xd = *reinterpret_cast<float*>(&data[1]);
yd = *reinterpret_cast<float*>(&data[5]);
pwm13 << PERIOD - (int)(PERIOD * std::min(1.0f, std::abs(xd)));
pwm14 << PERIOD - (int)(PERIOD * std::min(1.0f, std::abs(yd)));
}
else if(zf && cf) // set respective duty cycles
{
xd = 0.0F;
yd = 0.0F;
pwm13 << PERIOD;
pwm14 << PERIOD;
}
gpio30.flush();
gpio31.flush();
gpio48.flush();
gpio60.flush();
pwm13.flush();
pwm14.flush();
}
示例11: seekwriting
void seekwriting(unsigned long int& seekpos) {
ofs_.clear();
ofs_.seekp(B_HEADERSIZE+seekpos);
}
示例12: createILF
unsigned int ilf::createILF( std::istream &infile, std::ofstream &outfile )
{
unsigned int total = 0;
char temp[512];
// Write form with dummy size
unsigned int form0Position = outfile.tellp();
writeFormHeader( outfile, 0, "INLY" );
// Write form with dummy size
unsigned int form1Position = outfile.tellp();
writeFormHeader( outfile, 0, "0000" );
while( !infile.eof() )
{
unsigned int nodeSize = 0;
infile.getline( temp, 512, ':' );
if( infile.eof() ) { break; };
std::string objectFilename;
infile >> objectFilename;
std::cout << objectFilename << std::endl;
nodeSize += static_cast<unsigned int>( objectFilename.size() + 1 );
infile.getline( temp, 512, ':' );
std::string objectZone;
infile >> objectZone;
std::cout << objectZone << std::endl;
nodeSize += static_cast<unsigned int>( objectZone.size() + 1 );
// 'Transform matrix:' line
infile.getline( temp, 512, ':' );
std::cout.flags ( std::ios_base::showpoint );
std::cout << std::dec;
std::cout.flags( std::ios_base::fixed );
float x[12];
for( unsigned int i = 0; i < 12; ++i )
{
std::cout.width( 10 );
infile >> x[i];
nodeSize += sizeof( float );
std::cout << x[i] << " ";
}
std::cout << std::endl;
// Blank line
infile.getline( temp, 512 );
total += writeRecordHeader( outfile, "NODE", nodeSize );
outfile.write( objectFilename.c_str(),
static_cast<unsigned int>( objectFilename.size()+1 )
);
outfile.write( objectZone.c_str(),
static_cast<unsigned int>( objectZone.size()+1 )
);
outfile.write( (char*)x, sizeof( float ) * 12 );
total += nodeSize;
}
// Rewrite form with proper size.
outfile.seekp( form1Position, std::ios_base::beg );
total += writeFormHeader( outfile, total+4, "0000" );
// Rewrite form with proper size.
outfile.seekp( form0Position, std::ios_base::beg );
total += writeFormHeader( outfile, total+4, "INLY" );
return total;
}
示例13: closefile
void closefile(){
ply_file.seekp(pos);
ply_file << i;
ply_file.close();
}
示例14: seek
uint64_t seek(const uint64_t offs) { m_fp.seekp(offs,std::ios::beg); return m_fp.tellp(); }
示例15: writeNewFiles
size_t ZipArchive::writeNewFiles(std::ofstream& ofs,
std::vector<ZipArchive::ArchivedFile>& newFiles)
{
size_t counter = 0;
bool error = false;
for (size_t i = 0; i < newFiles.size(); ++i) {
if (newFiles[i].isNewInArchive_ == false) {
LWARNING("writeNewFiles(): attempting to add an existing or non-physical file '");
LWARNING(newFiles[i].fileName_ << "' as new file!\n");
continue;
}
if ((newFiles[i].extFileName_.empty() == true) && (newFiles[i].extHandle_ == 0)) {
LERROR("wirteNewFiles(): the external file name for the new file is empty!");
continue;
}
if (newFiles[i].fileName_.size() > 0xFFFF) {
LERROR("writeNewFiles(): the file name may not exceed (2^16 - 1) bytes!");
continue;
}
if ((FileSystem::fileExists(newFiles[i].extFileName_) == false) && (newFiles[i].extHandle_ == 0)) {
LERROR("file '" << newFiles[i].extFileName_ << "' does not exist!");
continue;
} else
LINFO("Writing file " << newFiles[i].fileName_);
// Seek forward from the current position to skip the LocalFileHeader struct and the file
// name. The space has to be kept free until we know all details which are available
// when deflateToDisk() has finished.
//
std::streampos archiveOffset = ofs.tellp();
ofs.seekp(SIZE_ZIPLOCALFILEHEADER + newFiles[i].fileName_.size(), std::ios_base::cur);
unsigned long crc32 = 0;
size_t compressedSize = 0;
size_t uncompressedSize = 0;
if ((newFiles[i].extFileName_.empty() == false) && (newFiles[i].extHandle_ == 0)) {
RegularFile inFile(newFiles[i].extFileName_);
compressedSize = deflateToDisk(inFile, ofs, crc32);
uncompressedSize = inFile.size();
} else if (newFiles[i].extHandle_ != 0) {
compressedSize = deflateToDisk(*(newFiles[i].extHandle_), ofs, crc32);
uncompressedSize = newFiles[i].extHandle_->size();
}
error = (compressedSize == 0);
// The compressed data now have been written and the header + file name
// can be inserted.
//
if (error == false) {
ZipLocalFileHeader& lfh = newFiles[i].zipLocalFileHeader_;
lfh.signature = 0x04034b50;
lfh.versionNeeded = ZIP_VERSION;
lfh.generalPurposeFlag = 0;
lfh.compressionMethod = 0x0008;
lfh.lastModTime = 0; // Argh! Need last modification time of file in DOS (!) style...
lfh.lastModDate = 0; // Argh! Need last modification date of file in DOS (!) style...
lfh.crc32 = crc32;
lfh.compressedSize = static_cast<uint32_t>(compressedSize);
lfh.uncompressedSize = static_cast<uint32_t>(uncompressedSize);
lfh.filenameLength = static_cast<uint16_t>(newFiles[i].fileName_.size());
lfh.extraFieldLength = 0;
// Seek the position where the LocalFileHeader has to be placed
//
ofs.seekp(archiveOffset, std::ios_base::beg);
ofs.write(reinterpret_cast<char*>(&lfh), SIZE_ZIPLOCALFILEHEADER);
error = ofs.fail();
}
if (error == false) {
ofs.write(newFiles[i].fileName_.c_str(), newFiles[i].fileName_.size());
error = ofs.fail();
}
if (error == true) {
LERROR("writeNewFiles(): an error has occured while writing to archive!");
break;
} else {
// The stream position is now again at the beginning of the block containing
// the compressed data, so seek forward to find the position where the
// next file can be written.
//
ofs.seekp(compressedSize, std::ios_base::cur);
// Adjust the state of the file within this archive: it is not new any longer
// and the file name has been adjusted. Furthermore the file now has a
// offset for the LocalFileHeader within this new archive...
//
newFiles[i].isNewInArchive_ = false;
newFiles[i].localHeaderOffset_ = static_cast<uint32_t>(archiveOffset);
newFiles[i].fileExtra_ = "";
newFiles[i].fileComment_ = "";
// In addition, the entry for the Central Directory can be created.
//
ZipFileHeader& fileHeader = newFiles[i].zipFileHader_;
//.........这里部分代码省略.........