Simple version :)
This simple program generates a sequence of sample values for a sine wave, and then writes them to a WAV file using the RIFF format. It includes code to write the RIFF header, the format chunk, and the data chunk, as well as the necessary fields for the sample rate, number of channels, and bits per sample.
If you want to write an MP3 file using C++, you will need to use an external library or tool to perform the MP3 encoding. There are many such libraries and tools available, both open source and commercial, which can be used to encode audio data into the MP3 format. Some examples of libraries and tools that you could use for this purpose include:
libmp3lame: an open source library for encoding MP3 files, available as part of the LAME project (http://lame.sourceforge.net/) ffmpeg: an open source library and command-line tool for encoding and decoding various audio and video formats, including MP3 (https://ffmpeg.org/) Audacity: an open source audio editor and recording application that can be used to export audio to the MP3 format (https://www.audacityteam.org/) LAME: a command-line tool for encoding MP3 files, based on the libmp3lame library (http://lame.sourceforge.net/) To use one of these libraries or tools to write an MP3 file using C++, you would first need to integrate the library or tool into your C++ project. This would typically involve compiling the library or tool, and linking it to your C++ code. You would then need to use the API provided by the library or tool to perform the MP3 encoding. This would typically involve passing the audio data to be encoded, as well as the necessary configuration parameters, to the library or tool, and then writing the resulting MP3 data to a file.
Overall, while it is not possible to write an MP3 file using C++ directly, you can use an external library or tool to perform the MP3 encoding and write the resulting data to a file. This will require some additional work to integrate the library or tool into your C++ project, but it will provide the necessary capabilities to write MP3 files using C++.