Linking .cpp Files

Hi!
I have made many small apps. A calculator, a game and many more, all text based. I want to make an app that lets you decide what app you want to use. So if you type in "Calculator", it opens calculator in the same console window. So I was thinking that to prevent overcrowding one .cpp file, I can store the source code for each app in different .cpp files. But I am a bit confused as to how to do this. I have not really found the answer to this, even though I've been Googling it for a long time.
Thanks!

P.S. Sorry if this is a bit unclear.
P.P.S. No jargon, please. Plain English.
Last edited on
Hi there,

You will need to use #include in order to achieve this.
If you google "c++ multifile programs" you will find a great amount of articles explaining this in detail.

Hope that helps.

All the best,
NwN
Yes, separate each app into its own cpp. You'll also need to have a .h for each of those .cpp of the same name.

Then, use the include directive to add all of those .h files into ur main .cpp

example:
calculator.cpp (has all of the implementations to ur calculator app)
calculator.h ( has all of the declarations/function prototypes to ur calculator app)

then in ur console u have:
main.cpp
#include "calculator.h"
closed account (o1vk4iN6)
I think it would be better to keep the programs separate and than just create a script to choose which program to run. A game shouldn't be compiled with a calculator, just doesn't make sense to me.
I am trying to achieve something like the Mac OS X Terminal App.
I don't know what the terminal app is, but like xerzi said you shouldn't be compiling them all together, you should have one program with a menu that opens the programs of whatever the user selects, of course this isn't exactly easy unless you know your OS's API, do some googling.
I am trying to achieve something like the Mac OS X Terminal App.
Note that the Mac OS X Terminal App does not compile all of the programs it can access into one bit executable (like your OP asked how to do). It does, like others have suggested, access those programs that the user wants to open externally.

If you want it to be a custom and specific terminal for your apps then there's a bit of work and it'll depend on the OS you plan to use it on.

If you're looking for a quick way to open an executable you could use
1
2
system("mycalculator.exe"); //windows
system("./mycalculator.bin") //linux; 



ps:
Of course, you could just use the cmd prompt provided with whichever OS you have to access release versions of your apps.
Last edited on
So there's another thing I've been trying to do without success. When the user finishes using one program it automatically goes back to the app selection page. I tried an infinite loop but I didn't succeed...As always :-p How is this possible? Oh and soranz, you said:
If you're looking for a quick way to open an executable you could use
system("mycalculator.exe"); //windows

I tried that but it didn't work. Any ideas?
Last edited on
closed account (o1vk4iN6)
You could create a shell script or bat script instead of a program.
Last edited on
u need the header: #include <cstdlib>
Topic archived. No new replies allowed.