当前位置: 首页>>代码示例>>C++>>正文


C++ ifstream::gcount方法代码示例

本文整理汇总了C++中ifstream::gcount方法的典型用法代码示例。如果您正苦于以下问题:C++ ifstream::gcount方法的具体用法?C++ ifstream::gcount怎么用?C++ ifstream::gcount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ifstream的用法示例。


在下文中一共展示了ifstream::gcount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: assertWarning

bool sfheader :: readWavHeader(ifstream &f, const char *name) {
	bool formatFound = false;
	unsigned char format[16];
	unsigned char data[12];
	f.read(data,12);
	if (!assertWarning(f.gcount() == 12,"Error reading header") ||
		!assertWarning(strncmp((char*)data, "RIFF", 4) == 0, "not RIFF file") ||
		!assertWarning(strncmp((char*)data+8, "WAVE", 4) == 0, "not WAV file"))
		return false;
	while (!f.eof()) {		// read chunks until data is found
		f.read(data,8);
		if (!assertWarning(f.gcount() == 8,"Error reading header"))
			return false;
		int chunkLength = sRead32LE(data+4);
		if (strncmp((char*)data, "data", 4) == 0) {
			if (!assertWarning(formatFound, "No format data in WAV file"))
				return false;
			init(chunkLength / (sizeof(audioSample) * sRead16LE(format+2)),
				 sRead32LE(format+4), sRead16LE(format), sRead16LE(format+2),
				 0, 0, name);
			return true;
		} else if (strncmp((char*)data, "fmt ", 4) == 0) {
			f.read(format,16);
			if (!assertWarning(f.gcount()==16, "Error in WAV format data") ||
				!assertWarning(sRead16LE(format) == WAV_LINEAR_PCM,
								"not WAV linear PCM format") ||
				!assertWarning(sRead16LE(format+14) == 16, "not 16 bit format"))
				return false;
			f.seekg(chunkLength-16, ios::cur);
			formatFound = true;
		} else
			f.seekg(chunkLength, ios::cur);
	}
	return assertWarning(false, "WAV data not found");
} // readWavHeader()
开发者ID:ruohoruotsi,项目名称:Riddim,代码行数:35,代码来源:sfheader.cpp

示例2: readModel

bool MlMaximumEntropyModel::readModel(ifstream& ifs)
{
	char buffer[256];
	while (ifs.good())
	{
		ifs.getline(buffer,256);
		if (ifs.gcount()>0 && buffer[0]!='#')
			break;
	}
		
	unsigned int numClasses=0;
	if (sscanf(buffer,"MAXIMUM_ENTROPY %u",&numClasses) != 1)
	{
		cout << "Bad line in model file:" << endl << buffer << endl;
		return false;
	}

	weights_.resize(numClasses);
	for (size_t c=0; c<numClasses; c++)
	{
		ifs.getline(buffer,256);
		unsigned int numWeights=0;
		if (sscanf(buffer,"%u",&numWeights) != 1)
		{
			cout << "Bad line in model file:" << endl << buffer << endl;
			return false;
		}
		weights_[c].resize(numWeights,0.0);
		while (ifs.good())
		{
			ifs.getline(buffer,256);
			if (! strncpy(buffer,"END_",4))
				break;
			if (ifs.gcount() == 0 || buffer[0] != 'F')
				continue;

			size_t index;
			float  weight;
			istringstream iss(buffer+1);
			iss >> index >> weight;
			if (iss.fail())
			{
				if (strlen(buffer)<3)
					continue;

				cout << "Bad line in model file:" << endl << buffer << endl;
				return false;
			}
			if (index>weights_[c].size())
				error("Bad feature index in line: ",buffer);

			weights_[c][index]=weight;
		}
	}
	return true;
}
开发者ID:benpullman,项目名称:mscluster2,代码行数:56,代码来源:mlmaximumentropy.cpp

示例3: sizeof

bool lemur::index::InvDocList::binReadC(ifstream& inf) {
  if (inf.eof())
    return false;
  int diff;

  inf.read((char*) &uid, sizeof(lemur::api::TERMID_T));
  if (!(inf.gcount() == sizeof(lemur::api::TERMID_T)))
    return false;

  inf.read((char*) &df, LOC_Tsize);
  if (!inf.gcount() == LOC_Tsize)
    return false;

  inf.read((char*) &diff, LOC_Tsize);
  if (!inf.gcount() == LOC_Tsize)
    return false;

  inf.read((char*) &size, LOC_Tsize);
  if (!inf.gcount() == LOC_Tsize)
    return false;

  //  unsigned char* buffer = (unsigned char*) malloc(size);
  // use new/delete[] so an exception will be thrown if out of memory.
  unsigned char* buffer = new unsigned char[size];
  inf.read((char*) buffer, size);
  if (!inf.gcount() == size) {
    resetFree();
    return false;
  }

  // this should be big enough
  //  begin = (LOC_T*) malloc(size*4);  
  // use new/delete[] so an exception will be thrown if out of memory.
  begin = new lemur::api::LOC_T[(size*4)/sizeof(lemur::api::LOC_T)];  

  // decompress it
  int len = lemur::utility::RVLCompress::decompress_ints(buffer, (int *)begin, size);

  size = size*4;

  if (len * LOC_Tsize > size)
    cerr << "RVLDecompress in DocList buffer overrun!" << endl;

  lastid = begin + diff;
  end = begin + len;
  freq = lastid+1;

  deltaDecode();

  READ_ONLY = false;
  //  free(buffer);
  delete[](buffer);
  return true;
}
开发者ID:busjaeger,项目名称:cs410sp12,代码行数:54,代码来源:InvDocList.cpp

示例4: convertchan2beam

void convertchan2beam( ifstream& datastrm) {
  ostringstream ossmsg;

	int pktSize = chanpkt1.getDataSize() + sizeof(beamHdr);

  for (;;) {
    datastrm.read((char *) &chanpkt1, pktSize);  
    if (datastrm.gcount() != pktSize) {
      if (datastrm.eof()) return;  // EOF should occur on this read 
      ossmsg << "(1) unexpected data file read count " <<
        dec << datastrm.gcount();
      mylog(ossmsg);
      exit(EXIT_FAILURE);
    }
    chanpkt1.marshall();
    memcpy( reinterpret_cast<void *>(&beamHdr), 
	reinterpret_cast<void *>(&chanpkt1), sizeof(beamHdr)) ;
    
    datastrm.read((char *) &chanpkt2, pktSize);  
    if (datastrm.gcount() != pktSize) {
      ossmsg << "(2) unexpected data file read count " <<
        dec << datastrm.gcount();
      mylog(ossmsg);
      exit(EXIT_FAILURE);
    }
    chanpkt2.marshall();
    short2char(reinterpret_cast<signed char *>(beampkt.getData()),
		reinterpret_cast <signed short *>(chanpkt1.getData()),
		reinterpret_cast <signed short *>(chanpkt2.getData()),
      		chanpkt1.getDataSize());


    // sanity check for 0xaabbccdd endian order value
    if (beamHdr.order != ATADataPacketHeader::CORRECT_ENDIAN) {
      mylog("output packet header does not contain 0xaabbccdd endian value");
      exit(EXIT_FAILURE);
    } 
    // fix some of the fields to make packets look like they came
    // from the beamformer
    beamHdr.src = ATADataPacketHeader::BEAM_104MHZ;  // not really 
    beamHdr.chan = 1;
    beamHdr.seq = sequence_num++;
    beamHdr.len = 2048;
    memcpy( reinterpret_cast<void *>(&beampkt), 
		reinterpret_cast<void *>(&beamHdr), sizeof(beamHdr));
    // write the SonATA channelizer compatible packet to stdout
    cout.write((char *) &beampkt, pktSize); 
  }
}
开发者ID:KenSmolek,项目名称:SonATA,代码行数:49,代码来源:packetchan2beam.cpp

示例5: ConcatenateAllReads

void ConcatenateAllReads(char * array, ifstream& file)
{
	int bufsize = 200000000;
	char* buff = new char[bufsize];
	long counter = 0;
	file.seekg(0, ios::beg);
	while(!file.eof())
	{
		cerr<<"begin read"<<endl;
		file.read(buff,bufsize);
		int numberofCharRead = file.gcount();

		cerr<<"end read"<<endl;
		for(int i = 0 ; i < numberofCharRead ; i++)
		{
			if(buff[i] == 'A' || buff[i] == 'T' || buff[i] == 'G' || buff[i] == 'C' )
			{
				array[counter] = buff[i];
				counter++;
			}
		} 
		cerr<<"end filter "<<endl;
	}
	return;
}
开发者ID:pashadag,项目名称:Pdb,代码行数:25,代码来源:ab.cpp

示例6: send_file_piece

// Trimite chunk de fisier
void send_file_piece(char *buffer, int cli_sock, ifstream& file)
{
	unsigned int i;
	bool found = false;
	for (i = 0; i < clienti.size(); ++i)
		if (clienti[i].sock == cli_sock)
		{
			found = true;
			cerr << "FOUNDDDD \n";
			break;
		}

	char bufbig[BUFFILE];
	memset(bufbig, 0, BUFFILE);

	if(found && clienti[i].size_fis)
	{
		file.read(bufbig, BUFFILE);
		clienti[i].size_fis -= file.gcount();
		cerr << "Remaining " << clienti[i].size_fis << " bytes to transfer\n";

		int n = send(cli_sock, bufbig, sizeof(bufbig), 0);
		send_verify(n);

		parse_recv_file(buffer, cli_sock);
	}
}
开发者ID:costash,项目名称:Communication-Protocols-Assignments,代码行数:28,代码来源:client.cpp

示例7: readDataToInputBuffer

/*
 *
 *  @param infile file to read
 *  @param count  record count to read
 *  @param data   save records

 *  @return  real readed counts
 */
int  readDataToInputBuffer(ifstream &infile,int count,Product * data)
{
    //read by page 4KB(4*1000 bytes),40 records take one page,read time=(count-1)/40+1
    char buffer[kPageSize+1];
    buffer[kPageSize]='\0';
    int  readTimes=(count-1)/40+1;
    int i=0,j=0;
    string line;
    for (i=0; i<readTimes; i++)
    {
        infile.read(buffer, kPageSize);
        if (infile.gcount()==0)     //文件结束
        {
            return 0;
        }
        istringstream istrstreamOfBuffer(buffer);
        while(getline(istrstreamOfBuffer,line))
        {
            istringstream istrstream(line);
            int  ID;
            float  price;
            istrstream>>ID>>price;                                    //get ID,price
            data[j].setId(ID);
            data[j].price=price;
            j++;
        }
    }
       return j;
}
开发者ID:sanyeshi,项目名称:mac,代码行数:37,代码来源:main.cpp

示例8: ConcatenateAllReads

void ConcatenateAllReads(char* array, ifstream& file)
{
	int bufsize = 200000000;
	//char buff[bufsize];
	char* buff = new char[bufsize];
	long counter = 0;
	cout<<"begin read"<<endl;
	while(!file.eof())
	{
		file.read(buff,bufsize);
		long numberofCharRead = file.gcount();

		for(long i = 0 ; i < numberofCharRead ; i++)
		{
			if(buff[i] == 'A' || buff[i] == 'T' || buff[i] == 'G' || buff[i] == 'C' )
			{
				array[counter] = buff[i];
				counter++;
			}
		} 
	}
	delete buff;
	cout<<"end filter "<<endl;
	return ;
}
开发者ID:pashadag,项目名称:Pdb,代码行数:25,代码来源:validate.cpp

示例9: readPlayerFromBinary

bool readPlayerFromBinary(Player& player, ifstream& input)
{
    assert(input.good());
    Player plr;
    input.read((char*)&plr, sizeof(plr));
    bool result = input.good() && input.gcount() == sizeof(plr);
    if (result) player = plr;
    return result;
}
开发者ID:dianvaltodorov,项目名称:learning-code,代码行数:9,代码来源:Player.cpp

示例10: FileSize

size_t FileSize(ifstream& is) {
  const streampos pos = is.tellg();
  is.clear();
  is.seekg(is.beg);
  is.ignore(numeric_limits<streamsize>::max());
  const size_t size = is.gcount();
  is.clear(); //clear EOF (set by ignore)
  is.seekg(pos);
  return size;
}
开发者ID:ugovaretto,项目名称:zmq-scratch,代码行数:10,代码来源:file-send.cpp

示例11: readSndHeader

bool sfheader :: readSndHeader(ifstream &f, const char *name) {
	unsigned char tmp[24];
	f.read(tmp,24);
	if (!assertWarning(f.gcount() == 24,"sfheader: reading header") ||
		!assertWarning(strncmp((char*)tmp, ".snd", 4) == 0,
						"sfheader: not .snd file"))
		return false;
	init(sRead32BE(tmp+8) / (sizeof(audioSample) * sRead32BE(tmp+20)),
		 sRead32BE(tmp+16), sRead32BE(tmp+12), sRead32BE(tmp+20), 0, 0, name);
	if (!assertWarning(format==SUN_LINEAR_PCM, "sfheader: PCM format expected"))
		return false;
	textlength = sRead32BE(tmp+4) - 24;
	text = new char[textlength+1];
	text[textlength] = 0;
	f.read(text,textlength);
	if (!assertWarning(f.gcount() == textlength,"sfheader: reading text field"))
		return false;
	return true;
} // readSndHeader()
开发者ID:ruohoruotsi,项目名称:Riddim,代码行数:19,代码来源:sfheader.cpp

示例12: _GetStream

void _GetStream(ifstream & fin, string & strBuf)
{
    fin.read(buf, MAX_CHAR_IN);

    int size = fin.gcount();
    buf[size] = 0;

    strBuf.clear();
    strBuf = buf;
    strlcnt = 0;
}
开发者ID:wenbostar,项目名称:pLink-SS,代码行数:11,代码来源:StringUtility.cpp

示例13: readInt

unsigned int BMPReader::readInt(ifstream &file)
{
	char buf[] = "0000";
	
	file.read(buf, 4);
	if(file.gcount() != 4)
	{
		throw runtime_error("111 File not read");
	}

	//cout<<"buf[0] = "<<getUnsignedInt(buf[0])<<" buf[1] = "<<getUnsignedInt(buf[1])<<" buf[2] = "<<getUnsignedInt(buf[2])
	  //    <<" buf[3] = "<<getUnsignedInt(buf[3])<<endl;

	return getIntInRightOrder(buf);
}
开发者ID:tipe,项目名称:searchbycolor,代码行数:15,代码来源:BMPReader.cpp

示例14: SendNextChunk

/*
 * Send the next chunk of the firmware file
 */
bool FirmwareTransferer::SendNextChunk() {
  uint8_t page[FLASH_PAGE_LENGTH];
  m_firmware->read(reinterpret_cast<char*>(page),
                   FLASH_PAGE_LENGTH);
  std::streamsize size = m_firmware->gcount();

  if (!size) {
    m_sucessful = true;
    cout << endl;
    return true;
  }
  cout << ".";
  fflush(stdout);
  return m_widget->SendMessage(FLASH_PAGE_LABEL, page, size);
}
开发者ID:mlba-team,项目名称:open-lighting,代码行数:18,代码来源:usbpro-firmware.cpp

示例15: do_md5

/* 取文件头,中间,末尾三部分数据计算MD5值 */
bool do_md5(ifstream &is, unsigned long long size, string &md5) 
{
	MD5_CTX ctx;
	MD5_Init(&ctx);

	char tmp[MD5_DATA_LEN] = {0};
	is.read(tmp, sizeof(tmp));
	unsigned long ret = is.gcount();
	MD5_Update(&ctx, tmp, ret);

	long m = (size - 1) / 2;
	if (m < 0) m = 0;
	is.seekg(m, ios_base::beg);
	is.read(tmp, sizeof(tmp));
	ret = is.gcount();
	MD5_Update(&ctx, tmp, ret);

	m = size - MD5_DATA_LEN;
	if (m < 0) m = 0;
	is.seekg(m,ios_base::beg);
	is.read(tmp, sizeof(tmp));
	ret = is.gcount();
	MD5_Update(&ctx, tmp, ret);

	unsigned char _md5[MD5_DIGEST_LENGTH] = {0};
	MD5_Final(_md5, &ctx);

	for(int i = 0; i < MD5_DIGEST_LENGTH; i++) {
		unsigned char c = _md5[i];
		int k1 = c >> 4;
		int k2 = c & 0xF;
		md5 += k1 >= 10 ? 'a' + (k1-10) : k1 - 0 + '0';
		md5 += k2 >= 10 ? 'a' + (k2-10) : k2 - 0 + '0';
	}
	return true;
}
开发者ID:00nanhai,项目名称:Lcc,代码行数:37,代码来源:my_md5.cpp


注:本文中的ifstream::gcount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。