0

How do do several programs in one file?

for example i write a program, and then i want to do a completely diffrent program, should I state int main () again?

31st Aug 2018, 3:06 AM
kumar Quiroz
kumar Quiroz - avatar
6 Answers
+ 1
kumar Quiroz I don't clearly get what you said. If it's all in one source file, it's not several programs, but modules/namespaces/libraries instead. A C++ program has 1 and only 1 function named main, which served as the entry point for the program.
31st Aug 2018, 4:53 AM
Hoàng Nguyễn Văn
Hoàng Nguyễn Văn - avatar
+ 1
thank you :))
31st Aug 2018, 5:21 AM
kumar Quiroz
kumar Quiroz - avatar
0
Each program will have their own project and groups of files, for example: //Program 1 main.cpp runGame.h rungame.cpp endGame.h endGame.cpp renderGraphics,h renderGraphics.cpp // Program 2 main.cpp math.h math.cpp input.h input.cpp output.h output.cpp These all live in their own folder structures and are written completely separately.
31st Aug 2018, 3:56 AM
Jeff Cales
0
I meant several programs in one file :)
31st Aug 2018, 3:59 AM
kumar Quiroz
kumar Quiroz - avatar
0
for example int main () { int x=4; cout<< x <<endl; return 0; } /* now i want to do another program under the above program, should i state int main again? */
31st Aug 2018, 4:59 AM
kumar Quiroz
kumar Quiroz - avatar
0
kumar Quiroz write your other statements after std::cout, before return 0, in main.
31st Aug 2018, 5:03 AM
Hoàng Nguyễn Văn
Hoàng Nguyễn Văn - avatar