本文整理汇总了C++中std::ofstream::tellp方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::tellp方法的具体用法?C++ ofstream::tellp怎么用?C++ ofstream::tellp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ofstream
的用法示例。
在下文中一共展示了ofstream::tellp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: writeArrayToBinaryFileStream
static void writeArrayToBinaryFileStream(std::ofstream& fileStream,
const T* array, const size_t sizeOfArray) {
assert_gt(sizeOfArray, 0);
auto bufferSize = (std::streamsize)(sizeOfArray * sizeof(T));
auto previousNumberOfBytes = fileStream.tellp();
assert_true(fileStream.write(reinterpret_cast<const char*>(array), bufferSize));
auto currentNumberOfBytes = fileStream.tellp();
assert_eq(bufferSize, currentNumberOfBytes - previousNumberOfBytes);
}
示例4: memcpy
// Write out the LLVM symbol table as an archive member to the file.
void
Archive::writeSymbolTable(std::ofstream& ARFile) {
// Construct the symbol table's header
ArchiveMemberHeader Hdr;
Hdr.init();
memcpy(Hdr.name,ARFILE_LLVM_SYMTAB_NAME,16);
uint64_t secondsSinceEpoch = sys::TimeValue::now().toEpochTime();
char buffer[32];
sprintf(buffer, "%-8o", 0644);
memcpy(Hdr.mode,buffer,8);
sprintf(buffer, "%-6u", sys::Process::GetCurrentUserId());
memcpy(Hdr.uid,buffer,6);
sprintf(buffer, "%-6u", sys::Process::GetCurrentGroupId());
memcpy(Hdr.gid,buffer,6);
sprintf(buffer,"%-12u", unsigned(secondsSinceEpoch));
memcpy(Hdr.date,buffer,12);
sprintf(buffer,"%-10u",symTabSize);
memcpy(Hdr.size,buffer,10);
// Write the header
ARFile.write((char*)&Hdr, sizeof(Hdr));
#ifndef NDEBUG
// Save the starting position of the symbol tables data content.
unsigned startpos = ARFile.tellp();
#endif
// Write out the symbols sequentially
for ( Archive::SymTabType::iterator I = symTab.begin(), E = symTab.end();
I != E; ++I)
{
// Write out the file index
writeInteger(I->second, ARFile);
// Write out the length of the symbol
writeInteger(I->first.length(), ARFile);
// Write out the symbol
ARFile.write(I->first.data(), I->first.length());
}
#ifndef NDEBUG
// Now that we're done with the symbol table, get the ending file position
unsigned endpos = ARFile.tellp();
#endif
// Make sure that the amount we wrote is what we pre-computed. This is
// critical for file integrity purposes.
assert(endpos - startpos == symTabSize && "Invalid symTabSize computation");
// Make sure the symbol table is even sized
if (symTabSize % 2 != 0 )
ARFile << ARFILE_PAD;
}
示例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: end
void end(char*,std::size_t){
file
<<"{"
<<"\"type\":\"FeatureCollection\","
<<"\"features\":[";
bool done=false;
for(std::size_t idx=0;idx<lon.size()&&!done;++idx){
file
<<"{"
<<"\"type\":\"Feature\","
<<"\"geometry\":"
<<"{"
<<"\"type\":\"Point\","
<<"\"coordinates\":["<<lon[idx]<<","<<lat[idx]<<"]"
<<"}"
<<"}";
file.flush();
if((std::size_t)(file.tellp())+file_thresh>=file_lim)
done=true;
else
file<<",";
}
file
<<"]"
<<"}";
}
示例7: write
void BezierCurves::write(std::ofstream& file)
{
int type = BEZIER_CURVES;
file.write((char*)&type,sizeof(int));
file.write((char*)&numTimeSteps,sizeof(int));
file.write((char*)&numVertices,sizeof(int));
file.write((char*)&numCurves,sizeof(int));
for (size_t j=0; j<numTimeSteps; j++) {
while ((file.tellp() % 16) != 0) { char c = 0; file.write(&c,1); }
for (size_t i=0; i<numVertices; i++) file.write((char*)&vertex(i,j),sizeof(Vec3fa));
}
while ((file.tellp() % 16) != 0) { char c = 0; file.write(&c,1); }
for (size_t i=0; i<numCurves; i++) file.write((char*)&curve(i),sizeof(int));
}
示例8:
static void
_mark_session (std::ofstream& fs)
{
if (!fs) return;
std::time_t t = std::time (nullptr);
struct tm lt;
localtime_r (&t, <);
if (fs.tellp () > 0)
fs << "\n\n" << std::flush;
fs <<
"********************************************************************************\n"
" New Session:\n"
" @ " << std::setfill ('0')
<< std::setw (2) << lt.tm_hour << ":"
<< std::setw (2) << lt.tm_min << ":"
<< std::setw (2) << lt.tm_sec << " "
<< std::setw (2) << lt.tm_mon << "/"
<< std::setw (2) << lt.tm_mday << "/"
<< (lt.tm_year + 1900) << std::setfill (' ') << "\n" <<
"********************************************************************************\n"
<< std::endl;
}
示例9: if
std::ostream& LoggerImpl::getAppender()
{
if (pipe)
return *pipe;
else if (!fname.empty())
{
if (!outfile.is_open())
{
outfile.clear();
outfile.open(fname.c_str(), std::ios::out | std::ios::app);
counter.resetCount(outfile.tellp());
}
if (maxfilesize > 0)
{
if (counter.getCount() > maxfilesize)
{
doRotate();
counter.resetCount();
}
return tee;
}
else
return outfile;
}
else if (loghost.isConnected())
return udpmessage;
else
return std::cerr;
}
示例10: append
static void append(
std::ofstream & out, std::string const & filename,
std::vector< IndexEntry > & index
)
{
uint64_t const indexpos = IndexLoader::getIndexPos(filename);
libmaus2::autoarray::AutoArray< IndexEntry > subindex = IndexLoader::loadIndex(filename);
if ( subindex.size() )
{
uint64_t const datapos = subindex[0].pos;
uint64_t const datalen = indexpos-datapos;
// shift all towards zero
for ( uint64_t i = 0; i < subindex.size(); ++i )
subindex[i].pos -= datapos;
uint64_t const ndatapos = out.tellp();
for ( uint64_t i = 0; i < subindex.size(); ++i )
subindex[i].pos += ndatapos;
std::ifstream istr(filename.c_str(),std::ios::binary);
istr.seekg(datapos,std::ios::beg);
::libmaus2::util::GetFileSize::copy ( istr, out, datalen, 1 );
for ( uint64_t i = 0; i < subindex.size(); ++i )
index.push_back(subindex[i]);
}
}
示例11: 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++;
}
}
示例12: time
std::ofstream& Logger::LogStart(TLogLevel level){
char buffer[64];
if (logger_os.tellp() >= logger_max_file_size){
logger_os.close();
std::string renamed_file = logger_filename;
renamed_file.append(".backup");
if (file_exists(renamed_file.c_str())) remove (renamed_file.c_str());
rename(logger_filename.c_str(), renamed_file.c_str());
remove (logger_filename.c_str());
}
if (!file_exists(logger_filename.c_str())){
logger_os.close();
logger_os.open(logger_filename.c_str(), std::ios::out | std::ios::app);
if (logger_os.is_open()){
logger_messageLevel = loggger_wantedLevel;
}else{
logger_messageLevel = logNone; //prevent from sending data into the not opened stream
}
}
time_t thetime = time(0);
tm * ptm = std::localtime(& thetime);
strftime(buffer, sizeof(buffer), "%d.%m.%Y %H:%M:%S", ptm);// Format: 15.06.2009 20:20:00
logger_os << "-" << buffer << " " << ToString(level) << ": ";
return logger_os;
}
示例13: writeCentralDirectory
bool ZipArchive::writeCentralDirectory(std::ofstream& ofs,
const std::vector<ZipArchive::ArchivedFile>& files)
{
std::streampos offsetCD = ofs.tellp();
size_t sizeCD = 0;
bool error = false;
for (size_t i = 0; i < files.size(); ++i) {
const ZipFileHeader& fileHeader = files[i].zipFileHader_;
ofs.write(reinterpret_cast<const char*>(&fileHeader), SIZE_ZIPFILEHEADER);
sizeCD += SIZE_ZIPFILEHEADER;
error = ofs.fail();
size_t stringSize = files[i].fileName_.size();
sizeCD += stringSize;
if ((error == false) && (stringSize > 0) && (stringSize == fileHeader.filenameLength)) {
ofs.write(files[i].fileName_.c_str(), stringSize);
error = ofs.fail();
}
stringSize = files[i].fileExtra_.size();
sizeCD += stringSize;
if ((error == false) && (stringSize > 0) && (stringSize == fileHeader.extraFieldLength)) {
ofs.write(files[i].fileExtra_.c_str(), stringSize);
error = ofs.fail();
}
stringSize = files[i].fileComment_.size();
sizeCD += stringSize;
if ((error == false) && (stringSize > 0) && (stringSize == fileHeader.fileCommentLength)) {
ofs.write(files[i].fileComment_.c_str(), stringSize);
error = ofs.fail();
}
if (error == true) {
LERROR("writeCentralDirectory(): failed to write Central Directory Entry in zip archive!");
break;
}
} // for
ZipEOCDHeaderRecord eocd;
eocd.signature = SIGNATURE_ZIPEOCDHEADERRECORD;
eocd.numberOfDisk = 0;
eocd.numberOfDiskWithStartOfCD = 0;
eocd.numberOfEntriesInThisCD = static_cast<uint16_t>(files.size());
eocd.numberOfEntriesInCD = static_cast<uint16_t>(files.size());
eocd.sizeOfCD = static_cast<uint32_t>(sizeCD);
eocd.offsetStartCD = (offsetCD >= 0) ? static_cast<uint32_t>(offsetCD) : 0;
eocd.commmentLength = 0;
if (error == false) {
ofs.write(reinterpret_cast<char*>(&eocd), SIZE_ZIPEOCDRECORD);
error = ofs.fail();
}
return (! error);
}
示例14: write
void QuadMesh::write(std::ofstream& file)
{
int type = QUAD_MESH;
file.write((char*)&type,sizeof(int));
file.write((char*)&numTimeSteps,sizeof(int));
int numVerts = numVertices();
file.write((char*)&numVerts,sizeof(int));
int numQuads = quads.size();
file.write((char*)&numQuads,sizeof(int));
for (size_t j=0; j<numTimeSteps; j++) {
while ((file.tellp() % 16) != 0) { char c = 0; file.write(&c,1); }
for (size_t i=0; i<numVerts; i++) file.write((char*)vertexPtr(i,j),sizeof(Vec3fa));
}
while ((file.tellp() % 16) != 0) { char c = 0; file.write(&c,1); }
for (size_t i=0; i<numQuads; i++) file.write((char*)&quad(i),sizeof(Quad));
}
示例15: write
void TriangleMesh::write(std::ofstream& file)
{
int type = TRIANGLE_MESH;
file.write((char*)&type,sizeof(int));
file.write((char*)&numTimeSteps,sizeof(int));
int numVerts = numVertices();
file.write((char*)&numVerts,sizeof(int));
int numTriangles = triangles.size();
file.write((char*)&numTriangles,sizeof(int));
for (size_t j=0; j<numTimeSteps; j++) {
while ((file.tellp() % 16) != 0) { char c = 0; file.write(&c,1); }
for (size_t i=0; i<numVerts; i++) file.write((char*)vertexPtr(i,j),sizeof(Vec3fa));
}
while ((file.tellp() % 16) != 0) { char c = 0; file.write(&c,1); }
for (size_t i=0; i<numTriangles; i++) file.write((char*)&triangle(i),sizeof(Triangle));
}