本文整理汇总了C++中istream::read方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::read方法的具体用法?C++ istream::read怎么用?C++ istream::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类istream
的用法示例。
在下文中一共展示了istream::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readDouble
double readDouble(istream& in)
{
int num = sizeof(int64_t)/sizeof(char);
char* s = new char [num];
in.read(s, num);
int64_t d = *((int64_t*)s);
swap_endian(d);
double ans = *((double*)&d);
delete[] s;
return ans;
}
示例2: sizeof
void quake3_bsp_map::read_visibility_data(istream& stream) {
#ifndef NDEBUG
std::cout << "Reading visibility data" << std::endl;
#endif
int visibility_length = m_lumps[iVisibleDataOffset].length;
//Only read the visibility data if it exists
if (visibility_length) {
stream.seekg(m_lumps[iVisibleDataOffset].offset, std::ios_base::beg);
stream.read(reinterpret_cast<char*>(&m_raw_cluster_data.totalClusters), sizeof(int));
stream.read(reinterpret_cast<char*>(&m_raw_cluster_data.size), sizeof(int));
uint num_clusters = m_raw_cluster_data.totalClusters * m_raw_cluster_data.size;
m_raw_cluster_data.bitSet.resize(num_clusters);
stream.read(reinterpret_cast<char*>(&m_raw_cluster_data.bitSet[0]), sizeof(unsigned char) * num_clusters);
}
}
示例3: MotionJob
/*! @brief Constructs a SaveJob from stream data
@param time the time in ms to perform the save
@param input the stream from which to read the job specific data
*/
SaveJob::SaveJob(double time, istream& input) : MotionJob(Job::MOTION_SAVE)
{
m_job_time = time;
// Temporary read buffers.
unsigned int uintBuffer;
float floatBuffer;
// read in the save_position size
input.read(reinterpret_cast<char*>(&uintBuffer), sizeof(unsigned int));
unsigned int m_save_position_size = uintBuffer;
// read in the save position vector
m_save_position = vector<float>(m_save_position_size, 0);
for (unsigned int i=0; i<m_save_position_size; i++)
{
input.read(reinterpret_cast<char*>(&floatBuffer), sizeof(float));
m_save_position[i] = floatBuffer;
}
}
示例4: load
void load(istream &in){
ulint a_size;
in.read((char*)&a_size,sizeof(a_size));
in.read((char*)&terminator_position,sizeof(terminator_position));
for(ulint i=0;i<a_size;++i){
char_type a;
in.read((char*)&a,sizeof(a));
alphabet.insert(a);
}
F.load(in);
L.load(in);
}
示例5:
bool
SDKMeshHandler::doCanRead(istream& stream) const noexcept
{
SDKMESH_HEADER hdr;
if (stream.read((char*)&hdr, sizeof(hdr)))
{
return hdr.Version == SDKMESH_FILE_VERSION;
}
return false;
}
示例6: GetString
inline string GetString(istream& input,const char terminator='\0')
{
// TODO: make this check for FEOF condition! and also more efficient
char c=' ';
string s;
while (c!=terminator && input)
{
input.read(&c,sizeof(char));
s += c;
}
return s;
}
示例7: readImageData
void readImageData( istream& is, cv::Mat_<cv::Vec3b>& cimg, cv::Mat_<cv::Vec3f>& points, cv::Mat_<float>& dimg)
{
string ln;
getline( is, ln);
istringstream iss(ln);
cv::Size imgSz;
iss >> imgSz.height >> imgSz.width;
cimg = cv::Mat_<cv::Vec3b>( imgSz);
points = cv::Mat_<cv::Vec3f>( imgSz);
dimg = cv::Mat_<float>( imgSz);
const int sz = imgSz.width * imgSz.height;
const int pxlChunk = 3*sizeof(float) + 3*sizeof(byte);
const int totalBytes = sz * pxlChunk;
char* buff = (char*)malloc( totalBytes);
int readBytes = 0;
while ( readBytes < totalBytes)
{
is.read( &buff[readBytes], totalBytes-readBytes);
const int numBytesRead = is.gcount();
if ( numBytesRead <= 0)
break;
readBytes += numBytesRead;
} // end while
assert( readBytes == totalBytes);
for ( int i = 0; i < sz; ++i)
{
int j = i * pxlChunk; // Offset into read in buffer
// Read in points (with respect to origin)
cv::Vec3f p( *(float*)&buff[j], // X
*(float*)&buff[j+sizeof(float)], // Y
*(float*)&buff[j+2*sizeof(float)]); // Z (depth)
j += 3*sizeof(float); // Skip to colour bytes
cv::Vec3b c( (byte)buff[j], (byte)buff[j+1], (byte)buff[j+2]);
const int row = i / imgSz.width; // Integer division
const int col = i % imgSz.width;
cimg.at<cv::Vec3b>(row,col) = c;
points.at<cv::Vec3f>(row,col) = p;
dimg.at<float>(row,col) = p[2]; // Depth is just the Z value
} // end for
free(buff);
getline( is, ln); // Read end of line
} // end readImageData
示例8: read
int FixedLengthBuffer::read(istream& stream){
int recAddr = stream.tellg();
stream.clear();
this->clear();
this->packing = 0; //FALSE
stream.read(this->buffer, this->bufferSize);
if(!stream.good()){
stream.clear();
return recAddr;
}
return recAddr;
}
示例9: readData
void VHP_RowInfo::readData(istream &in) {
unsigned short n;
in.read((char *)&n,sizeof(n));
if (n != nbin) {
if (nbin > 0) {
delete [] pix;
delete [] org;
nbin = 0;
}
}
if (n < 1) {
return;
}
if (!nbin) {
nbin = n;
pix = new unsigned short [nbin+1];
org = new unsigned char [nbin];
}
in.read((char *)pix,(nbin+1)*sizeof(unsigned short));
in.read((char *)org,nbin*sizeof(unsigned char));
}
示例10: set
//--------------------------------------------------
bool ofBuffer::set(istream & stream){
clear();
if( stream.bad() ) return false;
char aux_buffer[1024];
std::streamsize size = 0;
stream.read(aux_buffer, 1024);
std::streamsize n = stream.gcount();
while( n > 0 ){
// we resize to size+1 initialized to 0 to have a 0 at the end for strings
buffer.resize(size+n+1,0);
memcpy(&(buffer[0])+size,aux_buffer,n);
size += n;
if( stream ){
stream.read(aux_buffer, 1024);
n = stream.gcount();
}
else n = 0;
}
return true;
}
示例11: formatHash
PWIZ_API_DECL string SHA1Calculator::hash(istream& is)
{
CSHA1 sha1;
is.clear();
is.seekg(0);
unsigned char buffer[65535];
while (is && is.read(reinterpret_cast<char*>(buffer), 65535))
sha1.Update(buffer, 65535u);
sha1.Update(buffer, is.gcount());
sha1.Final();
return formatHash(sha1);
}
示例12: unserialize
static bool unserialize(string &str,istream &input)
{
static int len;
if (!Serialize::unserialize(len,input))
{
cerr << "Could not read the length of the string" << endl;
return false;
}
str.resize(len);
input.read(const_cast<char*>(str.data()),len);
return true;
};
示例13: ReadParams
void Mach::ReadParams(istream &inpf, bool with_alloc)
{
debug0("*** read params of type Mach\n");
switch (Mach::fileid) {
case file_header_version1: // read int but store ulong
unsigned int itmp;
inpf.read((char*) &itmp, sizeof(int)); nb_forw = (ulong) itmp;
inpf.read((char*) &itmp, sizeof(int)); nb_backw = (ulong) itmp;
debug2("V1 read int counters %lu/%lu\n",nb_forw,nb_backw);
break;
case file_header_version2:
case file_header_version3:
case file_header_version4:
inpf.read((char*) &nb_forw, sizeof(ulong));
inpf.read((char*) &nb_backw, sizeof(ulong));
debug2("V2 to V4 read ulong counters %lu/%lu\n",nb_forw,nb_backw);
break;
default:
Error("internal error, fileid is unset");
}
}
示例14: ReadStandard
void MidiEvent::ReadStandard(istream &stream) {
switch (Type()) {
case MidiEventType_NoteOff:
case MidiEventType_NoteOn:
case MidiEventType_Aftertouch:
case MidiEventType_Controller:
case MidiEventType_PitchWheel:
stream.read(reinterpret_cast<char*>(&m_data1), sizeof(unsigned char));
stream.read(reinterpret_cast<char*>(&m_data2), sizeof(unsigned char));
break;
case MidiEventType_ProgramChange:
case MidiEventType_ChannelPressure:
stream.read(reinterpret_cast<char*>(&m_data1), sizeof(unsigned char));
m_data2 = 0;
break;
default:
throw MidiError(MidiError_UnknownEventType);
}
}
示例15: 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);
}