Search code examples
c++standardsprogram-entry-point

main() function live in a .cpp file with the same name as my project in c++


I am new in c++ programing and as I am learning, I've saw this hint:

"It’s a good idea to have your main() function live in a .cpp file with the same name as your project."

I have no clear visual idea how this look. Can someone help me understand how this example work?

And is this example programing standard?


Solution

  • I have no clear visual idea how this look.

    Well, let's say your project is named MyProject so you should have a source file MyProject.cpp that contains the main() function:

    #include <iostream>
    
    int main(int argc, char* argv[]) {
        std::cout << "This is MyProject" << std::endl;
    }
    

    Something like the above is often automatically generated by a sensible IDE that manages your project containing several source and header files.


    And is this example programing standard?

    There aren't any real standards about how to name source files.