本文整理汇总了C++中stringstream::read方法的典型用法代码示例。如果您正苦于以下问题:C++ stringstream::read方法的具体用法?C++ stringstream::read怎么用?C++ stringstream::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stringstream
的用法示例。
在下文中一共展示了stringstream::read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readRaw
void readRaw(stringstream& stream, T& data) {
stream.read((char*) &data, sizeof(T));
}
示例2: parse
void gra_world_link::parse(string &choose, stringstream& ss,int)
{
if(choose == "task_c")
{
for(int i = 0; i < my_gra.MuLin_task_num; ++i)
{
ss.read((char*)&my_gra.MuLin_task[i].play_on, sizeof(bool));
ss.read((char*)&my_gra.MuLin_task[i].state, sizeof(double));
}
for(int i=0; i<my_gra.MuLin_part_num; ++i)
{
ss.read((char*)&my_gra.MuLin_show[i],sizeof(bool));
}
ss.read((char*)&my_gra.mulin_pos,sizeof(virw_position));
ss.read((char*)&my_gra.mulin_distortion, sizeof(virw_position));
ss.read((char*)(&my_gra.Cr), sizeof(double));
ss.read((char*)(&my_gra.Cg), sizeof(double));
ss.read((char*)(&my_gra.Cb), sizeof(double));
ss.read((char*)(&my_gra.Ca), sizeof(double));
ss.read((char*)(&my_gra.fog.density), sizeof(float));
ss.read((char*)(&my_states.time_big), sizeof(int));
ss.read((char*)(&my_states.time_small), sizeof(int));
ss.read((char*)(&my_states.world_run_count), sizeof(unsigned int));
ss.read((char*)(&my_gra.head_eye_angle), sizeof(double)*2);
ss.read((char*)(&my_gra.elevator_height), sizeof(double));
int conet=0;
while(my_gra.net_flush!=false&&my_gra.refresh_by_net&&conet<30)
{
conet++;
usleep(1000);
}
my_gra.net_flush = true;
}
else if(choose=="bmp123")
{
ss.read(my_gra.eye_picture,480*270*3);
my_gra.eye_pic_ch=true;
my_gra.big_paint.put_rect(0,330,480,270,(unsigned char*)my_gra.eye_picture);
}
else if(choose=="chk_gt")
{
my_gra.eye_focus=my_gra.mulin_pos;
my_gra.eye_focus.y-=my_gra.mulin_distortion.y;
my_net.send_to("chk_rg",NULL,0);
}
else if(choose == "grains")
{
int num;
ss.read((char*)&num, 4);
for(int i = 0; i < num; ++i)
{
ss.read((char*)&(my_gra.grains[i].model_id), sizeof(int));
ss.read((char*)&(my_gra.grains[i].pos), sizeof(float_virw_position));
ss.read((char*)&(my_gra.grains[i].color), sizeof(float) * 3);
}
my_gra.live_grain_num = num;
}
else if(choose == "fly_ea")
{
int num;
ss.read((char*)&num, 4);
for(int i = 0; i < num; ++i)
{
ss.read((char*)&(my_gra.fly_eats[i]), sizeof(float_virw_position));
ss.read((char*)&(my_gra.fly_eats_big[i]), sizeof(float));
ss.read((char*)&(my_gra.fly_eats_dead[i]), sizeof(bool));
}
my_gra.live_fly_eat_num = num;
}
else if(choose == "trees_")
{
int num;
ss.read((char*)&num, 4);
for(int i = 0; i < num; ++i)
{
ss.read((char*)&(my_gra.trees[i]), sizeof(float_virw_position));
ss.read((char*)&(my_gra.trees_big[i]), sizeof(float));
}
my_gra.live_tree_num = num;
}
else if(choose == "constr")
{
int num;
ss.read((char*)&num, 4);
for(int i = 0; i < num; ++i)
{
ss.read((char*)&(my_gra.cubes[i]), sizeof(long));
ss.read((char*)&(my_gra.cubes_color[i*4]), sizeof(float)*4);
}
my_gra.live_cube_num = num;
}
else if(choose == "meat_e")
{
int num;
ss.read((char*)&num, 4);
for(int i = 0; i < num; ++i)
{
ss.read((char*)&(my_gra.meat_eats[i]), sizeof(float_virw_position));
ss.read((char*)&(my_gra.meat_eats_big[i]), sizeof(float));
ss.read((char*)&(my_gra.meat_eats_dead[i]), sizeof(bool));
//.........这里部分代码省略.........
示例3: fillBuffer
uint32_t QueryableNetstringsDeserializerABCF::fillBuffer(istream& in, stringstream& buffer) {
char _c = 0;
uint32_t bytesRead = 0;
// Peek Container's header: 2 bytes (0xABCF) followed by maximum 8 bytes (uint64_t) length of payload information.
uint32_t bytesToRead = sizeof(uint16_t) + sizeof(uint64_t);
// Read Container header + size of payload.
while (in.good() && (bytesToRead > 0)) {
// Read next byte.
in.read(&_c, sizeof(char));
bytesToRead--; bytesRead++;
// Add new byte at the end of the buffer.
buffer.write(&_c, sizeof(char));
}
// Decode Container's magic number.
uint16_t magicNumber = 0;
buffer.read(reinterpret_cast<char*>(&magicNumber), sizeof(uint16_t));
magicNumber = ntohs(magicNumber);
if (magicNumber == 0xABCF) {
// Decode size of payload (encoded as varint).
uint64_t value = 0;
uint8_t size = 0;
{
while (buffer.good()) {
char c = 0;
buffer.read(&c, sizeof(char));
value |= static_cast<unsigned int>( (c & 0x7f) << (0x7 * size++) );
if ( !(c & 0x80) ) break;
}
// Decode as little endian like in Protobuf's case.
value = le64toh(value);
}
bytesToRead = (value // This is the length of the payload.
- (sizeof(uint64_t) // We have already read this amount of bytes while peeking the header.
- size) // This amount of bytes was consumed to encode the length of the payload in the varint field.
)
+ 1; // And we need to consume the final ','.
// Add the data at the end of the buffer.
buffer.seekg(0, ios_base::end);
// Read remainder of the container.
while (in.good() && (bytesToRead > 0)) {
// Read next byte.
in.read(&_c, sizeof(char));
bytesToRead--; bytesRead++;
// Add new byte at the end of the buffer.
buffer.write(&_c, sizeof(char));
}
// Move read pointer to the beginning to read container.
buffer.seekg(0, ios_base::beg);
}
return bytesRead;
}