PDA

View Full Version : main function in visual studio 2005




smilemoveon
Mar 2, 2008, 09:35 AM
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.



kainjow
Mar 2, 2008, 10:00 AM
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.

smilemoveon
Mar 2, 2008, 10:27 AM
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.

kainjow
Mar 2, 2008, 11:26 AM
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'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.

toddburch
Mar 2, 2008, 11:41 AM
The basics:
http://msdn2.microsoft.com/en-us/library/ms177549.aspx

The basic videos:
http://msdn2.microsoft.com/en-us/visualc/aa336415.aspx

Todd