main function in visual studio 2005

Discussion in 'Mac Programming' started by smilemoveon, Mar 2, 2008.

  1. macrumors newbie

    Feb 10, 2008
    Hello, I began to learn C++ in visual studio 2005. I create a new project A and new files, it seems that it allows only one main function in one project. For example, I create Hello.cpp with a main(), Stream.cpp with another main(), When I want to compile and run Stream.cpp, if I compile it using Building Solution or Build A, it will report error that _main already defined in Hello.obj. Currently I use comments to hide the main function in Hello.cpp to make Stream.cpp work.

    My question is:

    Is there any way I could compile the single file in a project, like only compile and run Stream.cpp in visual studio 2005?

    Or creat a single file without project?
    I tried to create a file without a project, but when I compile it, it still compile the project, any short cut for compiling single file? The menu only give me build solution or build A,

    I am not familiar with visual studio environmet and want to learn it, (pls do not suggest other environment like borland c as visual studio 2005 is the only one I can use now), It's very annoying to hide every main in previous files, any help would be much appreciated.
  2. Moderator emeritus


    Jun 15, 2000
    As far as I know, you need to create a project to compile any file in VS 2005. You cannot (like you're already noticed) have more than one main() function. If you have a file that already has main() and all your other code, just create a new project, delete any existing files, and add your file to the project.
  3. thread starter macrumors newbie

    Feb 10, 2008
    Thanks, kainjow:)

    In this case, how could I call another file in another project using system() function, or any way to access file in another project using specified path?

    I am learning Thinking in C++ and playing with the code, just want to try the system function.
  4. Moderator emeritus


    Jun 15, 2000
    I'm not sure what you mean, but if you have code in other file, you need to add it to your project to compile it and use it.

    system() is for calling system commands, like things you'd enter in the command prompt.
  5. macrumors 6502a

    Dec 4, 2006
    Katy, Texas

Share This Page