How to insert a buffer in a ostream with c++ -


what i'm trying insert stream ( std::ostream ) buffer .

this buffer attribute of class "acquisample"

i made example simple understand problem.

here definition of class :

class acquisample {   public:     iqsample * buffer; } 

here's definition of struct iqsample :

struct iqsample {  struct {     short val;  }i; struct {     short val;  }q; } 

what want put buffer known size stream that:

std::ostream stream; acquisample obj; stream << obj.buffer->i.val << obj.buffer->i.val; 

i think it's not working because it's not copying data pointer adress, want put entire buffer stream because i'm sending stream on computer.

if know how i'd thankful.

the idiomatic way achieve overload insertion operator:

struct iqsample {  struct {     short val;  }i; struct {     short val;  }q; };  std::ostream& operator<<( std::ostream& os, iqsample iqs ) {     return os << iqs.i.val << ' ' << iqs.q.val; // don't forget put white spaces between numbers! }  std::istream& operator>>( std::istream& os, iqsample& iqs ) {     return >> iqs.i.val >> iqs.q.val; } 

and now

std::ostream stream; // stream bound streambuf transfers on network acquisample obj; stream << *obj.buffer; 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -