have multiple codes in one project?

Hello!
I need to know if there is some way to have multiple codes in one C++ project. As in the main code, then some branching codes, but the entire thing fits in one .exe file.
Can someone tell me a way to do this?
and if there is none, can you tell me a way to "fake" this affect?
What do you mean?

Something like this?

1
2
3
4
5
int main()
{
    DoOneThing();
    DoAnotherThing();
}
Multiple codes? What?

If you mean multiple cpp files that compile to one program, then just compile the files at the exact same time (most IDEs have features to allow you to do this known as projects or solutions). Be sure that the variables/functions/objects are declared in both files (though for variables you'll need the extern keyword).

If you meant what Disch said, then...
http://cplusplus.com/doc/tutorial/functions/

-Albatross
Last edited on
uuummm...
Not what Disch said.
I mean multiple cpp files.
So I am able to have multiple cpp files in one project?
And when compiled, it makes 1 .exe?

Ok, so how do i do that?
lets say the main code is called "getthename" and the other is called "ihavethename."
If the user inputs "bill" into the main code, how could i make it run the second code?

this probably sounds all messed up.
It depends very much on your tools that you're using for compilation and/or your IDE.

-Albatross
Code::Blocks
just whatever it is that Code::Blocks uses by default
This isn't hard to do at all, but... Is what you're making really that large that you need to split it across several files?
Last edited on
There ought to be a button that permits you to add files to your project.

And @helios: Well... large size might not be the only reason someone splits stuff across several files.

-Albatross
Ok, that button I can find...
but how would i put a if:then statement that would change it from the main code to the secondary?
Create header file and a cpp file.

In your header file, declare (but do not define) a function. Include that header file in your main cpp file and your other file. In your other file, implement that function.

You may now use that function in your main code.

-Albatross
Topic archived. No new replies allowed.