Where to start?

Hi, does anyone know how to insert a sound file into a c++ program so that if I were to send it to a friend, but they didn't have the sound file that I have, they could still listen to it within the C++ program. I need to learn this because I want to build experience so that someday I can build a game with sound affects and such. Also...I am wondering if the console box that opens up could become the same thing as, let's say a minecraft console.
Last edited on
I suppose you could hardcode an array containing the same sequence of bytes in the sound file instead of loading a file at runtime, but I don't see why you can't just zip the executable and the sound file and send the archive. A lot easier, a lot faster.

As for the console, I don't know how minecraft's is, but if they did it I don't see why you can't too
How do you put a zip file into a c++ program? Can you put it into the main .cpp file? Oh, and i haven't heard the terminology archive in C++ yet, what do you mean?
Last edited on
closed account (Dy7SLyTq)
other way around jace. put the exe into the zip. i think archive is a compression term.
Can you put it into the main .cpp file?

Not in the way you're imagining it. You can put a file inside a program in the sense that you can write a copy of the bytes that make up the file into the program, but doing so is madness for various reasons.

By archive I simply meant the resulting zip|rar|tar file.
so once I have the zip file, where do I put it? I'm guessing I shouldn't put it into the .cpp or anything. What I'm trying to do is be able to post this program on a website, so people could (say...buy a game from my website). I'm not advanced enough to make a game right now, but I want to learn by diving in.

So in short, it would be very helpful if someone could tell me a way to include sound and songs into a C++ program (just like the music in mindcraft).
Thanks for the help so far.
Your program doesn't need nor should contain any asset data inside itself. What it should do is to load files and use those to work. Say your game.exe wants to play bgm.wav, then you put the wav in the directory where the game will look for sound files, so that the game can find it, load it and use it. If you don't understand about this you may want to look into some file I/O tutorials first.

When your game is finished you pack the exe and the assets in an archive so the users will need to download only the archive.
TL;DR programs don't contain files, they only load their content.

To play music you need some library that handles playing audio. The ones I know are DirectSound, OpenAL, FMOD, SDL, sfml. I'm currently struggling with OpenAL and I don't really recommend it as it has the worst documentation I've ever seen.
Last edited on
closed account (3qX21hU5)
To include sound in a program you are going to need to most likely learn how to use a sound library or in your case a game engine. In order to do that you need to be pretty experienced with C++ first, because it is not easy and damn near impossible if you don't have the basics of C++ down.

So my advice would be learn C++ first. Spend a year or two programming little programs in C++ and you should be at the point where you are experienced enough to know what you need to do.

If you are just beginning I recommend the books C++ Primer 5th edition and Accelerated C++ "Practical programming by example". Them are two good reputable books. Or you can just go through the tutorial here.

If you do want to look at some game engines I would recommend Orge 3D which is a good free graphical library. Or if you want to try your hand building a game engine you could look into directX or openGL or my favorite SFML 2.0 which is very simple to use and learn even for beginner C++ programmers.
Last edited on
K...so basically you're telling me that I probably shouldn't dive in headfirst into C++. So I should learn the basics of C++ first...though a year sounds like a long time....and then try all this. You guys seem pretty experienced, so I shall trust you. I guess I'll put my hopes of making a game within this year
aside...... :(
closed account (3qX21hU5)
It is still possible to make a small game within a year, but I just wanted to reinforce that programming a game and programming in general does not come easy and it doesn't come quickly. The general rule of thumb is if you want to be consider a quote "Expert" in programming it will take around 10,000 hours to accomplish and even then you are still learning all the time.

But anyways if you put some hard work and stick with it you could probably learn how to make a good little 2D game by yourself in a year or maybe under a year. Just don't go to fast all the basics will be used in whatever you do so it is good that you have a very good understanding of them.
Last edited on
K...I will try to learn. BTW:

I'm secretly Notch....

Last edited on
closed account (3qX21hU5)
I'm pretty sure Notch (That is if your talking about Markus Persson) already knows how to program in C++ ;p
Last edited on
Topic archived. No new replies allowed.