Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

smilemoveon

macrumors newbie
Original poster
Feb 10, 2008
21
0
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

Moderator emeritus
Jun 15, 2000
7,958
7
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

macrumors newbie
Original poster
Feb 10, 2008
21
0
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

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.