本文整理汇总了C++中ofstream::tellp方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::tellp方法的具体用法?C++ ofstream::tellp怎么用?C++ ofstream::tellp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofstream
的用法示例。
在下文中一共展示了ofstream::tellp方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例2: 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());
}
示例3: 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;
}
示例4: ExternaliseL
//============================================================================
// CTzCpString::ExternaliseL
//============================================================================
void CTzCpString::ExternaliseL(ofstream& aFilestream)
{
iOffset = (int)aFilestream.tellp() - iDocument.DbHeader()->iOffsetToStringTable;
TUint8 stringLength = iString.length();
aFilestream.write((char*)&stringLength,sizeof(stringLength));
aFilestream << iString.c_str();
}
示例5: switch_log
static bool switch_log(ofstream &flog)
{
GenerateTime("pacs_log\\%Y\\%m\\%d\\%H%M%S_service_n.txt", buff, sizeof(buff));
if(flog.tellp() > 10 * 1024 * 1024 || strncmp(buff, current_log_path.c_str(), 20)) // 20 == strlen("pacs_log\\YYYY\\MM\\DD\\")
{
if(PrepareFileDir(buff))
{
if(flog.is_open())
{
time_header_out(flog) << "to be continued" << endl;
flog.close();
}
flog.open(buff);
if(flog.fail())
{
cerr << "watch_notify() switch log " << buff << " failed" << endl;
return false;
}
time_header_out(flog) << "continuation of " << current_log_path << endl;
current_log_path = buff;
}
else
{
DWORD gle = GetLastError();
cerr << "watch_notify() switch log failed, PrepareFileDir(" << buff << ") failed" << endl;
return false;
}
}
return true;
}
示例6: OnMessage
void MQTTLogger::OnMessage(const struct mosquitto_message *message)
{
string topic = message->topic;
string payload = static_cast<const char*>(message->payload);
std::time_t tt = std::time(NULL);
char mbstr[100];
std::strftime(mbstr, sizeof(mbstr), "%Y-%m-%d %H:%M:%S:", std::localtime(&tt));
string time(mbstr);
Output << time + "\t" << topic + "\t" + payload << endl;
if (Output.tellp() > Max){
Output.close();
int i;
for (i = Number-1; i > 0; i--){
if (access((Path_To_Log + "." + to_string(i)).c_str(), F_OK) != -1){// check if old log file exists
if (rename((Path_To_Log + "." + to_string(i)).c_str(), (Path_To_Log + "." + to_string(i+1)).c_str()) != 0){
cerr << "can't create old log file \n";
exit(-1);
}
}
}
if (rename(Path_To_Log.c_str(), (Path_To_Log + ".1").c_str()) != 0){
cerr << "can't create old log file \n";
exit(-1);
}
Output.open(Path_To_Log);
if (!Output.is_open()){
cerr << "Cannot open log file for writting " << Path_To_Log << endl;
exit (-1);
}
mosquittopp::unsubscribe(NULL, Mask.c_str());// unsubscribe and subscribe to save all retained messages after rotate
Subscribe(NULL, Mask);
}
}
示例7: 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);
}
示例8: vcamOpenLog
void __stdcall vcamOpenLog(int verbosity, char* message)
{
#ifdef _DEBUG
{
CAutoLock l(&debugLock);
if (numUsers == 0) {
BOOL ok = CreateDirectory(VCAM_DEBUG_DIRNAME, NULL);
if (!ok && GetLastError() == ERROR_ALREADY_EXISTS)
{
ok = TRUE;
}
if (ok) {
try {
debugOut.exceptions(ios::failbit);
debugOut.open(VCAM_DEBUG_FNAME, ios_base::app);
// Truncate log if it's too big
debugOut.seekp(0, ios_base::end);
if (debugOut.tellp() > 1024 * 256) {
debugOut.close();
debugOut.open(VCAM_DEBUG_FNAME, ios_base::trunc);
}
openedOK = TRUE;
}
catch (...)
{
openedOK = FALSE;
}
}
else
{
openedOK = FALSE;
}
if (!openedOK && !showedLogWarning)
{
Msg("Couldn't open multicam log file,\r\nso no logging will be performed");
showedLogWarning = TRUE;
}
}
numUsers++;
}
vcamLog(verbosity, "%s opened log, numUsers = %d", message, numUsers);
#endif
}
示例9: sizeof
int
StatRandomVibrationSimulation::sampletofile(int nstep, ofstream& record)
{
long streampos=record.tellp();
//nt sz=U->Size();
// record.write(reinterpret_cast<const char*>(&time), sizeof(time));
//
double val;
for( int i=0 ; i<nstep; i++) {
val=(*samplExc)(i);
record.write(
reinterpret_cast<const char*>(&val), sizeof( val));
}
for(int i=0 ; i<nstep; i++) {
val=(*samplResp)(i);
record.write(
reinterpret_cast<const char*>(&val), sizeof( val));
}
record.flush();
return streampos;
}
示例10: ftellp
streampos ftellp(ofstream &fout) {
return fout.tellp();
}
示例11: CreateFile
void CRPSPreMF::CreateFile(ifstream &SamFile, ofstream &fp, int SamOrRps, vector<cds_word>* IndexClusterToLines){
cds_word *index;
size_t index_pos = 0;
getValuesPreSeq(posWin, WINSIZE); // get for last time the values from winSeq
for(cds_word j = 0; j < WINSIZE; j++) //free winSeq
delete [] WinSeq[j];
delete [] WinSeq;
if(tmp_file_string.length() > 0){
fileSeq << tmp_file_string; //write to fileQual (it must exist)
tmp_file_string = "";
}
ClusterIndex[ClusterIndex.size() - 1] = ClusterReads;
if(overlapcluster){ //add extra block if there is at least one read overlap with the next block
ClusterIndex.push_back((cds_word)-1);
if(IndexClusterToLines != NULL)
IndexClusterToLines->push_back(numberOfLines);
ClusterOverlap.push_back(overlapcluster);
}
fileSeq.close();
huffA = new Huffman(occ_notA, 249, true);
huffC = new Huffman(occ_notC, 249, true);
huffG = new Huffman(occ_notG, 249, true);
huffT = new Huffman(occ_notT, 249, true);
SaveValue(fp, ROW);
cout << "ClusterSize: " << ClusterOverlap.size() << endl;
cds_word novacio = 0;
for(cds_word i = 0; i < ClusterIndex.size() ; i++){
if(ClusterIndex[i] != (cds_word)-1)
novacio++;
}
cout << "No vacio: " << novacio << endl;
index = &ClusterIndex[0]; //Index data
if(ClusterIndex.size() != ClusterOverlap.size())
cout << "Error: Number of blocks created is not correct" << endl;
SaveValue(fp, (cds_word)ClusterIndex.size());
index_pos = fp.tellp();
SaveValue(fp, index, ClusterIndex.size());
SaveValue(fp, variableSize);
//if(variableSize){
index = &ClusterOverlap[0];
SaveValue(fp, index, ClusterOverlap.size());
//}
cds_word Variables[6];
Variables[0] = numberOfLinesNR; Variables[1] = numberOfLines; Variables[2] = sizeLine.size();
Variables[3] = preSeqLength; Variables[4] = (cds_word)(RNames.size()); Variables[5] = IndexRate;
SaveValue(fp, Variables, 6);
SaveValue(fp, &sizeLine[0], sizeLine.size());
for(cds_word i = 0; i < RNames.size(); i++){
SaveValue(fp, (cds_word)(RNames[i].length()));
SaveValue(fp, (char *)(RNames[i].c_str()), RNames[i].length());
SaveValue(fp, RNamesCluster[i]);
}
huffA->Save(fp); huffC->Save(fp); huffG->Save(fp); huffT->Save(fp);
init_preseq = fp.tellp();
init_preseq += 3 * sizeof(size_t);
SaveValue(fp, init_preseq);
SaveValue(fp, init_seq);
SaveValue(fp, end_seq);
buffer = init_buffer();
buffer_use = 0;
CompressPressumeSeq(fp, &buffer, &buffer_use);
init_seq = fp.tellp();
//RE-READ SAM FILE AND CREATE NEW FILE
ComputeCSeq(SamFile, fp, SamOrRps);
end_seq = fp.tellp();
fp.seekp(index_pos);
index = &ClusterIndex[0];
SaveValue(fp, index, ClusterIndex.size());
fp.seekp(init_preseq - 2 * sizeof(size_t));
SaveValue(fp, init_seq);
SaveValue(fp, end_seq);
remove(tmp_name.c_str());
fp.seekp(end_seq);
}
示例12: lengthFileLog
int Logger::lengthFileLog() {
fileLog.seekp(0, ios::end);
int fileLogSize = static_cast<int>(fileLog.tellp());
return fileLogSize;
}