本文整理汇总了C++中istream::seekg方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::seekg方法的具体用法?C++ istream::seekg怎么用?C++ istream::seekg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类istream
的用法示例。
在下文中一共展示了istream::seekg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readStream
void ScorePageBase::readStream(istream& testfile, int verboseQ) {
int binaryQ = 0; // to test if reading a binary or PMX data file.
if (&testfile == &cin) {
// presume that standard input is PMX data, and not binary data.
binaryQ = 0;
} else {
// The last 4 bytes of a binary SCORE file are 00 3c 1c c6 which equals
// the float value -9999.0.
testfile.seekg(-4, ios::end);
unsigned char databytes[4] = {0xff};
testfile.read((char*)databytes, 4);
if (databytes[0] == 0x00 && databytes[1] == 0x3c &&
databytes[2] == 0x1c && databytes[3] == 0xc6) {
binaryQ = 1;
} else {
binaryQ = 0;
}
testfile.seekg(0, ios::beg);
}
if (binaryQ) {
readBinary(testfile, verboseQ);
} else {
readPmx(testfile, verboseQ);
}
}
示例2: getStreamSize
static size_t getStreamSize(istream& stream) {
auto startPosition = stream.tellg();
stream.seekg(0, ios_base::end);
auto fileSize = static_cast<size_t>(stream.tellg());
stream.seekg(startPosition);
return fileSize;
}
示例3:
bool Point3Dot::load(istream &in){
coords.resize(3);
int start = in.tellg();
for(int i = 0; i < 3; i++){
in >> coords[i];
if(in.fail()){
in.clear();
in.seekg(start+1); //????????? Why that one
return false;
}
}
in >> theta;
if(in.fail()){
in.clear();
in.seekg(start+1); //????????? Why that one
return false;
}
in >> phi;
if(in.fail()){
in.clear();
in.seekg(start+1); //????????? Why that one
return false;
}
int typeInt;
in >> typeInt;
type = (Type)typeInt;
if(in.fail()){
in.clear();
in.seekg(start+1); //????????? Why that one
return false;
}
return true;
}
示例4: read_whole_stream
/* Reads a whole file/stream: somewhat inelegant */
string read_whole_stream(istream& in) {
in.seekg(0, ios::end);
string buf(in.tellg(), '$');
in.seekg(0, ios::beg);
in.read(&buf[0], buf.size());
return buf;
}
示例5: getChunkName
void
readsection(HeaderInfo &rwh, uint32 build, uint32 level, istream &rw)
{
for(uint32 i = 0; i < level; i++)
cout << " ";
string name = getChunkName(rwh.type);
cout << name << " (" << hex << rwh.length << " bytes @ 0x" <<
hex << rw.tellg()-(streampos)12 << "/0x" << hex << rw.tellg() <<
") - [0x" << hex << rwh.type << "] " << rwh.build << endl;
streampos end = rw.tellg() + (streampos)rwh.length;
while(rw.tellg() < end){
HeaderInfo newrwh;
newrwh.read(rw);
if(newrwh.build == build){
readsection(newrwh, build, level+1, rw);
/* Native Data PLG has the wrong length */
if(rwh.type == 0x510)
rw.seekg(end, ios::beg);
}else{
streampos sp = rw.tellg()+(streampos)rwh.length;
sp -= 12;
rw.seekg(sp, ios::beg);
break;
}
}
}
示例6: preprocess_input
string parser::preprocess_input(istream &stream)
{
streampos start = stream.tellg();
stream.seekg(0, ios::end);
streampos end = stream.tellg();
size_t file_size = end - start;
stream.seekg(start, ios::beg);
char bom_test[3];
static const char * BOM = "\xEF\xBB\xBF";
stream.read(bom_test, 3u);
if (strncmp(bom_test, BOM, 3u) == 0) {
// Matched BOM, keep stream position to prevent its reading
file_size -= 3u;
}
else {
// Seek stream back
stream.seekg(start, ios::beg);
}
char * buffer = new char[file_size + 1];
stream.read(buffer, file_size);
buffer[file_size] = '\0';
string s0(buffer);
delete[] buffer;
string s1 = fix_corrupted_data(s0);
return s1;
}
示例7: get_fsize
size_t get_fsize(istream& is)
{
size_t fsize = is.tellg();
is.seekg(0, std::ios::end);
fsize = size_t(is.tellg()) - fsize;
is.seekg(0, std::ios::beg);
return fsize;
}
示例8: BinaryReader
BinaryReader(istream &is): buffer(nullptr), size(0), pos(0) {
is.seekg (0, ios::end);
size = is.tellg();
is.seekg (0, ios::beg);
buffer = new char[size];
is.read(buffer, size);
is.seekg(0, ios::beg);
}
示例9: open_font
font font::open_font(istream& thefile,int ptsize,long index) {
thefile.seekg(0,ios::end);
int filesize=thefile.tellg();
thefile.seekg(0,ios::beg);
auto_ptr<vector<char> > filecont(new vector<char>(filesize));
thefile.read(&(*filecont)[0],filesize);
SDL_RWops* wop=SDL_RWFromConstMem(&(*filecont)[0],filesize);
TTF_Font* thefont = TTF_OpenFontIndexRW(wop,true,ptsize,index);
return font().build(thefont,filecont);
}
示例10: FrFileType
FrFILETYPE FrFileType(istream &in)
{
char buf[BUFFER_SIZE] ;
long pos = in.tellg() ;
in.seekg(0) ;
(void)in.read(buf,sizeof(buf)) ;
FrFILETYPE type = check_type(buf,in.gcount()) ;
in.seekg(pos) ;
return type ;
}
示例11: _getStreamSize
std::streampos Data::_getStreamSize(istream &stream) {
auto current_pos = stream.tellg();
//Retrieve length
stream.seekg(0, stream.end);
auto endpos = stream.tellg();
//Restore old position
stream.seekg(current_pos, stream.beg);
return endpos - current_pos;
}
示例12: sizeof
DecisionTreePtr DecisionTree::readC5(istream& in, AttributeSpec* spec)
{
int tag;
in.read((char*)&tag, sizeof(int));
if (memcmp((char *)&tag, "id=", 3) == 0)
{
in.seekg (0, ios::beg);
return readC5Text(in, spec);
}
in.seekg(0, ios::beg);
return readC5Bin(in, spec);
}
示例13: StreamIn
void JackPlugin::StreamIn (istream &s)
{
char Test;
int Version, NumInputs, NumOutputs;
s.seekg (2, ios::cur ); //skip to next line
Test = s.peek(); //peek first char
s.seekg (-2, ios::cur ); //jump back to prior line
if ( (Test >= '0') && (Test <= '9') )
{
s >> Version;
}
示例14: StreamIn
void SplitterPlugin::StreamIn (istream &s)
{
char Test;
int Version, Channels;
s.seekg (2, ios::cur );//skip to next line
Test = s.peek();//peek first char
s.seekg (-2, ios::cur );//jump back to prior line
if ( (Test >= '0') && (Test <= '9') )
{
s >> Version;
}
示例15: XING_LABEL_SIZE
XingStreamBase::XingStreamBase(int nIndex, NoteColl& notes, istream& in) : MpegStreamBase(nIndex, notes, in), m_nFrameCount(-1), m_nByteCount(-1), m_nQuality(-1)
{
fill(&m_toc[0], &m_toc[100], 0);
in.seekg(m_pos);
const int XING_LABEL_SIZE (4);
const int BFR_SIZE (MpegFrame::MPEG_FRAME_HDR_SIZE + 32 + XING_LABEL_SIZE); // MPEG header + side info + "Xing" size //ttt2 not sure if space for CRC16 should be added; then not sure if frame size should be increased by 2 when CRC is found
char bfr [BFR_SIZE];
int nSideInfoSize (m_firstFrame.getSideInfoSize());
int nBfrSize (MpegFrame::MPEG_FRAME_HDR_SIZE + nSideInfoSize + XING_LABEL_SIZE);
MP3_CHECK_T (nBfrSize <= m_firstFrame.getSize(), m_pos, "Not a Xing stream. This kind of MPEG audio doesn't support Xing.", NotXingStream()); // !!! some kinds of MPEG audio (e.g. "MPEG-1 Layer I, 44100Hz 32000bps" or "MPEG-2 Layer III, 22050Hz 8000bps") have very short frames, which can't accomodate a Xing header
streamsize nRead (read(in, bfr, nBfrSize));
STRM_ASSERT (nBfrSize == nRead); // this was supposed to be a valid frame to begin with (otherwise the base class would have thrown) and nBfrSize is no bigger than the frame
char* pLabel (bfr + MpegFrame::MPEG_FRAME_HDR_SIZE + nSideInfoSize);
MP3_CHECK_T (0 == strncmp("Xing", pLabel, XING_LABEL_SIZE) || 0 == strncmp("Info", pLabel, XING_LABEL_SIZE), m_pos, "Not a Xing stream. Header not found.", NotXingStream());
MP3_CHECK_T (4 == read(in, bfr, 4) && 0 == bfr[0] && 0 == bfr[1] && 0 == bfr[2], m_pos, "Not a Xing stream. Header not found.", NotXingStream());
m_cFlags = bfr[3];
MP3_CHECK_T ((m_cFlags & 0x0f) == m_cFlags, m_pos, "Not a Xing stream. Invalid flags.", NotXingStream());
if (0x01 == (m_cFlags & 0x01))
{ // has frames
MP3_CHECK_T (4 == read(in, bfr, 4), m_pos, "Not a Xing stream. File too short.", NotXingStream());
m_nFrameCount = get32BitBigEndian(bfr);
}
if (0x02 == (m_cFlags & 0x02))
{ // has bytes
MP3_CHECK_T (4 == read(in, bfr, 4), m_pos, "Not a Xing stream. File too short.", NotXingStream());
m_nByteCount = get32BitBigEndian(bfr);
}
if (0x04 == (m_cFlags & 0x04))
{ // has TOC
MP3_CHECK_T (100 == read(in, m_toc, 100), m_pos, "Not a Xing stream. File too short.", NotXingStream());
}
if (0x08 == (m_cFlags & 0x08))
{ // has quality
MP3_CHECK_T (4 == read(in, bfr, 4), m_pos, "Not a Xing stream. File too short.", NotXingStream());
m_nQuality = get32BitBigEndian(bfr);
}
streampos posEnd (m_pos);
posEnd += m_firstFrame.getSize();
in.seekg(posEnd); //ttt2 2010.12.07 - A header claiming to have TOC but lacking one isn't detected. 1) Should check that values in TOC are ascending. 2) Should check that it actually fits: a 104 bytes-long 32kbps frame cannot hold a 100 bytes TOC along with the header and other things.
}