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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:41:43+00:00 2026-06-18T10:41:43+00:00

I am writting function for create and save WAV file but I don’t know

  • 0

I am writting function for create and save WAV file but I don’t know how to send numbers to stream:

ofstream file;
file.open("sound.wav");
file << "RIFF";
file << (int) 32;
file << "WAVE";

I am trying to implement this WAVE file structure: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/

and problem is here the output is like this:

RIFF32WAVE
  • 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-06-18T10:41:44+00:00Added an answer on June 18, 2026 at 10:41 am

    The streaming operator << does formatted output – it converts values to text. This is not what you want for writing to a binary file format.

    Instead, you want to use the unformatted output functions: put for single bytes, and write for multiple bytes:

    file.write("RIFF", 4);
    
    // The length field is little-endian, so write the lowest byte first
    file.put(length);
    file.put(length >> 8);
    file.put(length >> 16);
    file.put(length >> 24);
    
    file.write("WAVE", 4);
    

    UPDATE: as noted in the comments, you should also open the file in binary mode and inbue it with the classic “C” locale, to prevent anything from messing around with the bytes you write:

    file.open("sound.wav", std::ios_base::out | std::ios_base::binary);
    file.imbue(std::locale::classic());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Open file, write to file, save file as a zip and stream
I'm currently writing a function what would create a zip file, which will be
I'm writting a function to take an invoice file in a defined format and
File in: compute = ...page.&#xD;o When you use the &#x201C;Create Form&#x201D; function ... Do...
I am writing a function in Haskell that deals with numbers beyond the length
I'm trying to create a flexible toggle function with jQuery where I take the
It is my first time to create a program with file reading and writing
I'm trying to create a function that will revert buffers from emacs' *Buffer List*
I tried writting a function which receives an input from the user as to
I want to create a signature for a file using OpenSSL. I believe that

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.