Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 74951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:26:20+00:00 2026-05-10T20:26:20+00:00

Is there a way to use these operators to input and output binary data?

  • 0

Is there a way to use these operators to input and output binary data? The reason I want to do this is that it makes the code readable. Ex: infile >> filedecrypter >> metadataparser >> audiodecoder >> effects >> soundplayer;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:26:21+00:00Added an answer on May 10, 2026 at 8:26 pm

    Indeed that can be done, if the library or your code provides the overloads for operator<< and operator>> for it to work. Simple example on how one could do it:

    class transformer {     public:     virtual std::iostream& transform(std::iostream&) = 0; };  class noise : public transformer {     public:     virtual std::iostream& transform(std::iostream&) {          /* extract, change and put into again */     } };   class echo : public transformer {     public:     virtual std::iostream& transform(std::iostream&) {          /* extract, change and put into again */     } };  std::iostream& operator>>(std::iostream& io, transformer& ts) {     return ts.transform(io); }  int main() {     std::stringstream data;     std::ifstream file('sound.wav');      noise n; echo e;      data << file.rdbuf();     data >> n >> e;     /* pipelined data now ready to be played back */ } 

    The problem with using a pure std::istream is that you would read, but then you wouldn’t have a way to put the transformed data back for the next step in the pipeline. Thus i’m using std::iostream here. This approach doesn’t seem to be efficient, as every operator>> call would extract the whole data, and put into again.

    To have a more performant way to stream this would be to create an expression template. This means, while operator>> is called, you don’t do the transforming yet, but you return expression types that will record the chain of operations within its type:

    typedef transform< echo< noise< istream > > > pipeline; std::ifstream file('file.wav'); pipeline pipe(file); int byte = pipe.get(); 

    would be an example of such a type. The pipelines’ structure is decoded into the type itself. Therefore, no virtual functions are needed anymore in the pipeline. It’s not constructed on-demand, but using typedef here, to show the principle. Programming such a system is not easy. So you probably should look into existing systems, like Boost.Iostreams (see below). To give you an idea how it would look like, here is an example i just coded up for you 🙂 :

    #include <iostream>  template<typename T> struct transformer {     int get() {         return static_cast<T*>(this)->read();     } };  struct echot {     template<typename Chain>     struct chain : transformer< chain<Chain> > {         Chain c;          int read() {             return c.get() + 1;         }          chain(Chain const& c):c(c) { }     }; } echo;  struct noiset {     template<typename Chain>     struct chain : transformer< chain<Chain> > {         Chain c;          int read() {             return c.get() * 2;         }          chain(Chain c):c(c) { }     }; } noise;   template<typename T> typename T::template chain<std::istream&> operator>>(std::istream& is, T) {     return typename T::template chain<std::istream&>(is); }  template<typename T, typename U> typename U::template chain<T> operator>>(T t, U u) {     return typename U::template chain<T>(t); }  int main() {     std::cout << (std::cin >> echo >> noise).get() << std::endl; } 

    Entering 0 yields the ASCII code 48 here, which is added 1, and multiplied by 2, yielding a value of 98, which is also finally output. I think you agree this is not some code a starter would want to write. So maybe look into boost.

    Boost has an sophisticated iostreams library, which can do many things. I’m sure you would find something fitting to this. Boost.Iostreams

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 100k
  • Answers 100k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ban in your coding standards the direct use of any… May 11, 2026 at 7:57 pm
  • Editorial Team
    Editorial Team added an answer Because tail is a List<T>, the compiler is telling you… May 11, 2026 at 7:57 pm
  • Editorial Team
    Editorial Team added an answer Use Convert.ToBase64String(byte[]) to convert it to base 64 representation and… May 11, 2026 at 7:57 pm

Related Questions

Kind of a random question... What I'm looking for is a way to express
We are releasing a paid web application. We have Google Analytics and want to
I'm writing powershell script that simulates actions performed by user on the page. I
I have a worker thread that is listening to a TCP socket for incoming

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.