So far I have three divided files. One header file, a cpp file and a main file. The problem is that when I run this program in one file it works out perfectly. Once I divide it into those three files, all hell brakes loose and it shows a bunch of garbage.
Here is what I have,
Don't include the .cpp file. In general, you should only include header files.
When you compile it, mention both cpp files on the compile line. They will both be compiled into object files and the object files will be linked into the executable (and then the object files will be deleted in this case).
Don't include the .cpp file. In general, you should only include header files.
I believe he was referring to "main" here. ".cpp" files should be kept separate, compiled separate and then linked together to form the ".exe" file. The Ide should take care of this for you. If you are working from the command line you could use a "make file" or you will have to use the command line to tell the compiler what files need to be compiled and then what files need to be linked.
You also wrote using namespace std; which introduces all the standard library names in the global namespace: IMHO, that means you’re doing your best to shoot yourself in the foot.
Last point. There are times where the order of include files does make a difference.
Because "iostream" and "string" come first anything in "Cake.h" that would need these header files will be covered.
The way you have it "Cake.h" comes first, but needs the "string" header file to cover the two "std::strings". Since the order in the ".cpp" file is backwards the ".h" file does not know about "string" yet and that is why you think you need to include "string" in the header file.