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 6626385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:53:11+00:00 2026-05-25T21:53:11+00:00

I want to temporarily cache binary data before I can write it to a

  • 0

I want to temporarily cache binary data before I can write it to a file. This was my idea.

Since I have to insert a header before this data that indicates how much data will follow after the header, I needed a way to keep this data cached before it is written to ofstream file. I decided to create ostream buffer(); wherein I could dump all this data without writing it to the file.

After the header was written, I’d just do file << buffer to dump the data.

I’m still struggling with compiler errors such as this one:

error: no matching function for call to ‘TGA2Converter::writePixel(std::ostream (&)(), uint32_t&)’
note: candidate is: void TGA2Converter::writePixel(std::ostream&, uint32_t)

Why am I getting this message? And, perhaps more importantly, am I approaching the problem in the most effective and convenient way?


Edit: people have been asking for code. I tried to narrow it down to this…

// This is a file. I do not want to write the binary
// data to the file before I can write the header.
ofstream file("test.txt", ios::binary);

// This is binary data. Each entry represents a byte.
// I want to write it to a temporary cache. In my
// real code, this data has to be gathered before
// I can write the header because its contents depend
// on the nature of the data.
stringstream cache;
vector<uint32_t> arbitraryBinData;
arbitraryBinData.resize(3);
arbitraryBinData[0] = 0x00;
arbitraryBinData[1] = 0xef;
arbitraryBinData[2] = 0x08;

// Write it to temporary cache
for (unsigned i = 0; i < arbitraryBinData.size(); ++i)
    cache << arbitraryBinData[i];

// Write header
uint32_t header = 0x80;     // Calculation based on the data!
file << header;

// Write data from cache
file << cache;

I fully expected this binary data to be written to the file:

0000000: 8000 ef08

But I got this:

0000000: 3132 3830 7837 6666 6638 6434 3764 3139
0000010: 38

Why am I not getting the expected result?

  • 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. Editorial Team
    Editorial Team
    2026-05-25T21:53:12+00:00Added an answer on May 25, 2026 at 9:53 pm

    ostream buffer(); is declaring a function called buffer taking no arguments and returning an ostream. Also ostream is a base class, you should be using strstream instead.

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

Sidebar

Related Questions

This function is global and is defined in the header file ( temporarily I
want to have a Hyperlink-Button in a gridView in which I can display a
I want to create a temporary cache lookup to speed up a file lookup
Suppose I have some data I want to post to a server. You're in
I have a nested, mutual recursive data structure , and want to associate computational
My app temporarily stores a lot of sensitive data and I want to overwrite
In Yii, I have enabled APC caching through the config/main.php file: 'cache' => array(
This is conjunction with my previous question https://stackoverflow.com/questions/8428911/jcs-disk-cache-data-retrieval Does JCS read from disk even
I do not want my Java SWT application to cache temporary internet files. Currently
Using WebRequest I want to know if I get a 302 Moved Temporarily response

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.