本文整理汇总了C++中ifstream::tellg方法的典型用法代码示例。如果您正苦于以下问题:C++ ifstream::tellg方法的具体用法?C++ ifstream::tellg怎么用?C++ ifstream::tellg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ifstream
的用法示例。
在下文中一共展示了ifstream::tellg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bytesRemainingToTheEnd
// This utilitu function returns the bytes remaining until the end of the file
// is reached. It should be probably made publicly availale in a separate util
// section of the library (e.g. util/io.h)
size_t bytesRemainingToTheEnd(ifstream& ifs) {
std::streampos tmp = ifs.tellg();
ifs.seekg(0, ifs.end);
size_t totalLength = ifs.tellg();
ifs.seekg(tmp);
return (totalLength - ifs.tellg());
}
示例2: processCentersWFN
/* ********************************************************************************************* */
void processCentersWFN(ifstream &ifil,const int nnu,string* &atlbl,solreal* &rr,solreal* &atch)
{
alloc1DStringArray("atlbl",nnu,atlbl);
alloc1DRealArray("rr",3*nnu,rr);
alloc1DRealArray("atch",nnu,atch);
string line;
int fipos,fepos;
size_t pos;
//bool isspace=true;
for (int i=0; i<nnu; i++) {
fipos=ifil.tellg();
getline(ifil,line);
fepos=ifil.tellg();
atlbl[i]=line.substr(0,12);
while (atlbl[i][0]==' ') {atlbl[i].erase(0,1);}
while (atlbl[i][atlbl[i].length()-1]==' ') {
atlbl[i].erase(atlbl[i].length()-1);
}
pos=atlbl[i].find_first_of(' ');
while (pos!=string::npos) {
atlbl[i].erase(pos,1);
pos=atlbl[i].find_first_of(' ');
}
line.erase(0,23);
//sscanf(line.c_str(),"%g %g %g",&rr[3*i],&rr[3*i+1],&rr[3*i+2]);
ifil.seekg(fipos+23);
ifil >> rr[3*i] >> rr[3*i+1] >> rr[3*i+2];
//cout << atlbl[i] << endl;
//cout << "R[" << i << "]: " << rr[3*i] << " " << rr[3*i+1] << " " << rr[3*i+2] << endl;
ifil.seekg(fipos+70);
ifil >> atch[i];
//cout << "Charge[" << i << "]: " << atch[i] << endl;
ifil.seekg(fepos);
}
}
示例3: read_bin_entry
// Method to read an entry from a binary file
// @param string filename - the name of the file which stores binary log entries
// @param streampos entry_position - the position of the log entry to be read
// @return BinaryLogEntry - the BinaryLogEntry struct containing all pertinent data
//
// Our binary log entry size is always the same. Some error checking
// should be performed to ensure bytes received are expected and
// and in correct order
// TODO current operation is dangerous and unreliable. A single missing byte will break all future log entry reading - use a delimination phrase between log entries, and scan accordingly
BinaryLogEntry read_bin_entry(string filename, streampos entry_position) {
Shakespeare::BinaryLogEntry log_entry;
static ifstream inputBinary;
inputBinary.open(filename.c_str(),ios_base::binary);
streampos abs_position = entry_position*sizeof(log_entry);
// store EOF conditions
inputBinary.seekg(0,ios::end);
size_t file_size;
file_size = inputBinary.tellg();
#ifdef CS1_DEBUG
printf ("End: filesize:%d,entries:%ld\n", file_size, file_size / sizeof(log_entry) );
#endif
// seek back to beginning of file
inputBinary.seekg(0,ios::beg);
if (entry_position > 0) {// seek as required
inputBinary.seekg(abs_position);
}
// take a reading if boundary conditions are met
int cur_pos = inputBinary.tellg();
if ( (unsigned)(file_size - cur_pos) >= sizeof(log_entry) ) {
if (inputBinary) { // read and return log entry
inputBinary.read( (char*)&log_entry, sizeof(log_entry) );
}
}
// close and return
inputBinary.close();
return log_entry;
}
示例4: GetFileSize
size_t CommonTools::GetFileSize(ifstream &fin)
{
streampos loc = fin.tellg();
fin.seekg(0, fin.end);
size_t size = fin.tellg();
fin.seekg(loc);
return size;
}
示例5: FileLength
size_t CommonFunction::FileLength(ifstream &file)
{
streampos current_pos = file.tellg();
file.seekg(0, ios::end);
size_t len = file.tellg();
file.seekg(current_pos);
return len;
}
示例6: get_file_size
/**
* Returns the size of the given file.
*/
int get_file_size(ifstream &ifs)
{
long begin, end;
begin = ifs.tellg();
ifs.seekg(0, ios::end);
end = ifs.tellg();
ifs.seekg(ios::beg);
return end - begin;
}
示例7: get_length
ifstream::pos_type get_length(ifstream &file)
/* Note that this function requires a binary file. */
{
auto current_position = file.tellg();
file.seekg(0, file.end);
auto file_length = file.tellg();
file.seekg(current_position);
return file_length;
}
示例8: GetFileLength
long GetFileLength(ifstream &ifs)
{
long tmppos;
long respos;
tmppos = ifs.tellg();
ifs.seekg(0, ios::end);
respos = ifs.tellg();
ifs.seekg(tmppos, ios::beg);
return respos;
}
示例9: getFileLength
unsigned long getFileLength(ifstream& file)
{ if(!file.good()) return 0;
unsigned long pos=file.tellg();
file.seekg(0,ios::end);
unsigned long len = file.tellg();
file.seekg(ios::beg);
return len;
}
示例10: size_of_stream
int size_of_stream(ifstream& f){
/* Save the current position. */
long save_pos = f.tellg( );
/* Jump to the end of the file. */
f.seekg(0, ios::end );
/* Get the end position. */
long size_of_file = f.tellg( );
/* Jump back to the original position. */
f.seekg( save_pos, ios::beg );
return( size_of_file );
};
示例11: _getFileLength
unsigned long CShaderMngr::_getFileLength(ifstream &inFile) const
{
if(!inFile.good()) return 0;
streamoff pos = inFile.tellg();
inFile.seekg(0,ios::end);
streamoff len = inFile.tellg();
inFile.seekg(pos);
return static_cast<unsigned long>(len);
}
示例12: filesize
long filesize(ifstream& f)
{
long current = f.tellg();
f.seekg(0, ios::beg);
long beg = f.tellg();
f.seekg(0, ios::end);
long end = f.tellg();
f.seekg(current, ios::beg);
return end-beg;
}
示例13: fileLength
unsigned long long fileLength(ifstream & file_stream)
{
unsigned long long old_position = (unsigned long long) file_stream.tellg();
file_stream.seekg(0, ios::end);
unsigned long long length = (unsigned long long) file_stream.tellg();
file_stream.seekg(old_position);
return length;
}
示例14:
JSize
JGetFStreamLength
(
ifstream& theStream
)
{
const long savedMark = theStream.tellg();
theStream.seekg(0, ios::end);
const JSize fileLength = theStream.tellg();
theStream.seekg(savedMark, ios::beg);
return fileLength;
}
示例15: getFileSize
size_t dami::getFileSize(ifstream& file)
{
size_t size = 0;
if (file.is_open())
{
streamoff curpos = file.tellg();
file.seekg(0, ios::end);
size = file.tellg();
file.seekg(curpos);
}
return size;
}