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


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

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


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

示例1: main

int main(int argc, char *argv[]) {
  if (argc != 2) {
    cout << "Parameters Error." << endl;
    cout << "Use: " << argv[0] << " xxxx.bmp" << endl;
    return 1;
  }

  bmpfile.open(argv[1], ios::in | ios::binary);
  if (bmpfile.is_open()) {
    bmpfile.read((char *)&FileHeader, sizeof(FileHeader));
    if (strncmp(FileHeader.bfType, "BM", 2) != 0) {
      cout << "Not a BMP File, or an Unsupported OS/2 BMP File." << endl;
      return 1;
    }
    bmpfile.read((char *)&InfoHeader, sizeof(InfoHeader));

    Output_FileHeader();
    Output_InfoHeader();

    vector<Pixel> *vec = ReadBitmap();

    int x, y;
    while (cin >> x >> y) {
      if (x == -1)
        break;
      PrintLocation(x, y, vec);
    }

    bmpfile.close();
    delete[] vec;
  } else {
开发者ID:taoky,项目名称:taoky.github.io,代码行数:31,代码来源:bmp1.cpp

示例2: rebuild

/*
 * Description: rebuild the file using header info
 * Arguments: in - reference to ifstream to use
 * Return Value: none
 */
void HCTree::rebuild(ifstream& in){
  stack<HCNode*> myStack;
  byte flag;
  in.read((char*)&flag, sizeof(flag));
  
  /* loop until the stack size is 1 and flag meets separator*/
  while (myStack.size()>1 || flag != 0 ) {
    if (flag == 1) { // this is a leaf node
      byte symbol;
      in.read((char*)&symbol,sizeof(symbol));
      HCNode* newNode = new HCNode(0, symbol, 0, 0, 0);
      leaves[(int)symbol] = newNode;
      myStack.push(newNode);
    } else if(!myStack.empty()){ // this is a internal node
      HCNode* c1 = myStack.top();
      myStack.pop();
      HCNode* c0 = myStack.top();
      myStack.pop();
      HCNode* mergeNode = new HCNode(0, 0, c0, c1, 0);
      c0->p = mergeNode;
      c1->p = mergeNode;
      myStack.push(mergeNode);
    }
    in.read((char*)&flag, sizeof(flag));
  }
  root = myStack.top();
  myStack.pop();
}
开发者ID:ericc572,项目名称:UCSD_CSE100_Winter2015,代码行数:33,代码来源:HCTree.cpp

示例3: ToHumanRead

vector<Pixel> *ReadBitmap() {
  int offset = 0;
  int height = ToHumanRead(InfoHeader.biHeight);
  int width = ToHumanRead(InfoHeader.biWidth);

  int linebyte = width * ToHumanRead(InfoHeader.biBitCount) / 8;
  offset = linebyte % 4;
  if (offset != 0)
    offset = 4 - offset;
  cout << "Offset: " << offset << endl;

  vector<Pixel> *vec = new vector<Pixel>[ abs(height) ];

  bool isBottom = false;
  if (ToHumanRead(InfoHeader.biHeight) > 0) // read from bottom
  {
    isBottom = true;
  }
  for (int i = 0; i < abs(height); i++) {
    for (int j = 0; j < width; j++) {
      bmpfile.read((char *)&p, sizeof(p));
      if (!isBottom)
        vec[i].push_back(p);
      else
        vec[height - i - 1].push_back(p);
      drop_alpha();
    }
    for (int j = 0; j < offset; j++) {
      unsigned char null;
      bmpfile.read((char *)&null, sizeof(null));
    }
  }
  return vec;
}
开发者ID:taoky,项目名称:taoky.github.io,代码行数:34,代码来源:bmp1.cpp

示例4: GetUInt

UINT32 DICOMParser::GetUInt(ifstream& fileDICOM, const DICOM_eType eElementType, const UINT32 iElemLength, const bool bNeedsEndianConversion) {
  string value;
  UINT32 result;
  switch (eElementType) {
    case TYPE_Implicit :
    case TYPE_IS  : {
              value.resize(iElemLength);
              fileDICOM.read(&value[0],iElemLength);
              result = atoi(value.c_str());
              break;
            }
    case TYPE_UL  : {
              fileDICOM.read((char*)&result,4);
              if (bNeedsEndianConversion) result = EndianConvert::Swap<UINT32>(result);
              break;
            }
    case TYPE_US  : {
              short tmp;
              fileDICOM.read((char*)&tmp,2);
              if (bNeedsEndianConversion) tmp = EndianConvert::Swap<short>(tmp);
              result = tmp;
              break;
            }
    default : result = 0; break;
  }
  return result;
}
开发者ID:burlen,项目名称:visit_vtk_7_src,代码行数:27,代码来源:DICOMParser.cpp

示例5: read_file

void flag_orbits::read_file(ifstream &fp, int verbose_level)
{
	int f_v = (verbose_level >= 1);
	int i;
	
	if (f_v) {
		cout << "flag_orbits::read_file" << endl;
		}
	fp.read((char *) &nb_primary_orbits_lower, sizeof(int));
	fp.read((char *) &nb_primary_orbits_upper, sizeof(int));
	fp.read((char *) &nb_flag_orbits, sizeof(int));
	fp.read((char *) &pt_representation_sz, sizeof(int));

	Pt = NEW_int(nb_flag_orbits * pt_representation_sz);
	for (i = 0; i < nb_flag_orbits * pt_representation_sz; i++) {
		fp.read((char *) &Pt[i], sizeof(int));
		}
	Flag_orbit_node = NEW_OBJECTS(flag_orbit_node, nb_flag_orbits);
	for (i = 0; i < nb_flag_orbits; i++) {
		if (FALSE) {
			cout << "flag_orbits::read_file "
					"node " << i << " / " << nb_flag_orbits << endl;
			}
		Flag_orbit_node[i].Flag_orbits = this;
		Flag_orbit_node[i].flag_orbit_index = i;
		Flag_orbit_node[i].read_file(fp, 0 /*verbose_level */);
		}

	if (f_v) {
		cout << "flag_orbits::read_file finished" << endl;
		}
}
开发者ID:abetten,项目名称:orbiter,代码行数:32,代码来源:flag_orbits.cpp

示例6: read

void AnimPackage::read(ifstream &ifp)
{
	SECTION_DECLARATION_2
	fourcc = readUInt32(ifp);
	size = readUInt32(ifp);

	if (fourcc == ANPK) {
		READ_SECTION(INFO);

		uint32 numAnims = readUInt32(ifp);
		animList.resize(numAnims);
		size -= sizeof(uint32);
		size = (size+0x3) & ~0x3;
		char *buf = new char[size];
		ifp.read(buf, size);
		name = buf;
		delete[] buf;

		for (uint32 i = 0; i < numAnims; i++)
			animList[i].read_1(ifp);
	} else if (fourcc == ANP3) {
		char buf[24];
		ifp.read(buf, 24);
		name = buf;
		uint32 numAnims = readUInt32(ifp);
		animList.resize(numAnims);

		for (uint32 i = 0; i < numAnims; i++)
			animList[i].read_3(ifp);
	} else {
		cout << "no known ifp file\n";
	}
}
开发者ID:aap,项目名称:gtatools,代码行数:33,代码来源:animread.cpp

示例7: loadMvsPatch

Patch FileLoader::loadMvsPatch(ifstream &file) {
	vector<int> camIdx;
	int camNum;
	Vec3d center;
	Vec2d sphericalNormal;
	double fitness;
	double correlation;

	// read patch center
	loadMvsVec(file, center);
	// read patch spherical normal
	loadMvsVec(file, sphericalNormal);
	// load visible camera number
	file.read((char*) &camNum, sizeof(int));
	// load visible camera index
	for (int i = 0; i < camNum; ++i) {
		int idx;
		file.read((char*) &idx, sizeof(int));
		camIdx.push_back(idx);
	}
	// load fitness
	file.read((char*) &fitness, sizeof(double));
	// load correlation
	file.read((char*) &correlation, sizeof(double));
	return Patch(center, sphericalNormal, camIdx, fitness, correlation);
}
开发者ID:yuhuangintel,项目名称:pais-mvs,代码行数:26,代码来源:fileloader.cpp

示例8:

	BitString::BitString(ifstream & input) {
		assert(input.good());
		input.read((char*)&length,sizeof(size_t));
		input.read((char*)&uintLength,sizeof(size_t));
		data = new uint[uintLength];
		input.read((char*)data,uintLength*sizeof(uint));
	}
开发者ID:rkonow,项目名称:libcds,代码行数:7,代码来源:libcdsBitString.cpp

示例9: readDevice

void HealthClub::readDevice (ifstream & inFile)
{
	//assumption - the file is open and set on the right place
	int i;

	int Serial;
	inFile.read((char*)&Serial, sizeof(Serial));//reading the serial number of device
	Device::SetSerialNum(Serial);
	
	int totalDevice;
	inFile.read((char*)&totalDevice, sizeof(totalDevice)); //reading the total amount of devices in the club

	this->devices.setLogicSize(totalDevice); //allocating device* array
	this->devices.getArray() = new Device*[totalDevice];

	//creating the devices according the info in the file 
	for (i = 0; i<this->devices.getLogicSize(); i++)
	{
		int length = 3;
		char* type = new char [length+1]; //indicate the type of the current device
		inFile.read((char*)type,length); // read the type of current device from the file
		type[length]= '\0';
		if (strncmp(type,typeid(AerobicDevice).name()+6, length) == 0)
		{
			Device* d = new AerobicDevice (inFile); // create from the file new aerobic device
			this->devices.replaceCell(i,d);
		}
		else if (strncmp(type,typeid(PowerDevice).name()+6,length) == 0)
		{
			Device* d =  new PowerDevice (inFile); // create from the file new Power device
			this->devices.replaceCell(i,d);
		}
	}
}
开发者ID:lior035,项目名称:CPP-WorkoutGym,代码行数:34,代码来源:healthClub.cpp

示例10: readClusterData

bool readClusterData(ifstream& inf, int* dataPts, int nPts, int nClusters, int ts_chunk, float** ctrs)
{
	if (!inf)
        return false;
	int value;
	float fvalue;
    for(int i=0; i < nPts; i++){
		//assert(inf);
		//if(!inf.eof()){
			inf.read(reinterpret_cast<char *>(&value), sizeof(int));
			//fprintf(stderr,"dataPts[%d]=%d\n",i,value);
			dataPts[i] = value;
			
		//}
	}

	//fprintf(stderr,"next_cluster\n");
	for (int j = 0; j < nClusters; j++){
		for (int d = 0; d < ts_chunk; d++) {
			inf.read(reinterpret_cast<char *>(&fvalue), sizeof(float));
			ctrs[j][d] = fvalue;
			//fprintf(stderr,"ctrs[%d][%d]=%f\n",j,d,ctrs[j][d]);
		}
	}

	return true;
}
开发者ID:sukharev,项目名称:ucd,代码行数:27,代码来源:clusterview2d.cpp

示例11: loadMvsCamera

PAIS::Camera FileLoader::loadMvsCamera(ifstream &file) {
	int fileNameLength;
	char *fileName;
	Vec3d center;
	Vec2d focal;
	Vec4d quaternion;
	Vec2d principle;
	double radialDistortion;

	// read image file name length
	file.read( (char*) &fileNameLength, sizeof(int) );
	// read image file name
	fileName = new char [fileNameLength+1];
	file.read(fileName, fileNameLength);
	fileName[fileNameLength] = '\0';
	// read camera center
	loadMvsVec(file, center);
	// read camera focal length
	loadMvsVec(file, focal);
	// read camera principle point
	loadMvsVec(file, principle);
	// read rotation quaternion
	loadMvsVec(file, quaternion);
	// read radial distortion
	file.read((char*) &radialDistortion, sizeof(double));

	Camera cam(fileName, focal, principle, quaternion, center, radialDistortion);

	delete [] fileName;

	return cam;
}
开发者ID:yuhuangintel,项目名称:pais-mvs,代码行数:32,代码来源:fileloader.cpp

示例12: dumpDiffBaselines

void dumpDiffBaselines(ifstream &fin1, ifstream &fin2)
{
    Baseline baseline1;
    Baseline baseline2;
    Baseline diffBaseline;

    // read in all the baselines
    while (fin1.read((char*)&baseline1, sizeof baseline1))
    {
	baseline1.demarshall();

	fin2.read((char*)&baseline2, sizeof baseline2);
	baseline2.demarshall();

	diffBaseline.header = baseline1.header;

	// diff the values
	for (int i=0; i< baseline1.header.numberOfSubchannels; ++i)
	{
	    diffBaseline.baselineValues[i] = 
		baseline1.baselineValues[i] - baseline2.baselineValues[i];
	}

	diffBaseline.marshall();
	cout.write((char*)&diffBaseline, sizeof diffBaseline);

    }
}
开发者ID:Abhishekpatil,项目名称:SonATA,代码行数:28,代码来源:diffSonATABaselines.cpp

示例13: read

bool ch_image_ref::read(f_base * pf, ifstream & fin, long long t)
{
  lock_bk();
  unsigned long long ul;
  m_time[m_back] = t;
  fin.read((char*) &m_ifrm[m_back], sizeof(long long));
  //  cout << "Frame index " << m_ifrm[m_back] << endl;
  fin.read((char*) &ul, sizeof(unsigned long long));
  //  cout << "Compressed Frame size " << ul << endl;
  Mat bufm(1, (int) ul, CV_8UC1);
  fin.read((char*) bufm.data, (streamsize) ul);

  imdecode(bufm, CV_LOAD_IMAGE_ANYDEPTH, &m_img[m_back]);
  //  cout << "Resulting image size " << m_img[m_back].cols << "x" << m_img[m_back].rows << endl; 
  //  cout << "Exiting ch_image::read" << endl;
  lock_fr();

  unlock_fr();
  int tmp = m_front;
  m_front = m_back;
  m_back = tmp;

  unlock_bk();
  return true;
}
开发者ID:d-zenju,项目名称:aws,代码行数:25,代码来源:ch_image.cpp

示例14: binarnoBranje

/*
  Ta funkcija prebere binarno datoteko.
*/
void binarnoBranje()
{
    //odpiranje datoteke
    inputFile.open(filename.c_str(), ios::binary|ios::in);
    //ugotavljanje velikosti datoteke:
    inputFile.seekg(0,inputFile.end);
    long long fileSize = inputFile.tellg();
    //pointer nazaj na zacetek datoteke
    inputFile.seekg(0,inputFile.beg);

    //preracunanje koliko je koncnih bytov, za katere bo treba prilagoditi char array in stevilo iteracij
    long long endBytes = fileSize % writingSize, pos = 0, iterations = fileSize/writingSize;
    //branje
    while (iterations--)
    {
        inputFile.read(c, writingSize);
        pos+=writingSize;
        inputFile.seekg(pos, ios::beg);
    }
    //koncni byti
    delete[] c;
    c = new char[endBytes];
    inputFile.read(c, endBytes);
    //velikost c nastavimo nazaj na zacetek
    delete[] c;
    c = new char[writingSize];
}
开发者ID:roklekse,项目名称:kopiranje,代码行数:30,代码来源:main.cpp

示例15: 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


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