Odeslat dotazOdeslat dotaz
 

OdpovědětSimple Answer for Simple Question

  • 2. července 2009 18:47cmbrooks08 Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     
    Hi guys-

    I know this is going to be very simple, so I apologize if you feel I've wasted your time.  I'm transitioning from NetBeans for Java to Visual C++.  In NetBeans, I used to keep a project that would just kind of be my testing ground where I would store random code I was working on, or labs for classes, etc.  I'm trying to figure out which project type will let me do the same in Visual C++.  I created an empty Visual C++ solution, added an empty project, and added about 3 source files.  Since they aren't all related, they all have a main function, and because of that, I can't build.  I just want to run one cpp file at a time, but I can't figure out how to to do it without building everything, which gives me the "more than one main declared" error.  I can't believe I couldn't find an answer to this anywhere else, but maybe no one else does this? I find that hard to believe, but anyways, can anyone point me in the right direction?

Odpovědi

  • 2. července 2009 19:40Brian MuthMVPUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Odpovědět
    There's no way to just have multiple .cpp files and right click and run (or something of the sort)? I don't want to have to build the whole project, I just want to compile the individual file and run.

    Just create a separate project for each .cpp file. You can have multiple projects in the same solution, which is very convenient.
  • 2. července 2009 20:02nobugzMVP, ModerátorUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Odpovědět
    Click, then Shift + Click to select all the files.  Right-click, Properties, General, set Excluded from Build = Yes.  Whatever file you want to try, set it back to No and build.  Avoid this problem in the future by keeping your main() in a separate source file.

    Hans Passant.

Všechny reakce

  • 2. července 2009 18:54Nishant SivakumarModerátorUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     

    Have a single main() from which you then call the test functions.  So you have main.cpp with the main() function, foo1.cpp with the Foo1() function, and foo2.cpp with the Foo2 class. Now to test foo1, you just call Foo1() from main(), and to test foo2, instantiate Foo2 in main and invoke methods on it. Repeat similarly for other classes/functions.


    http://blog.voidnish.com
  • 2. července 2009 18:58cmbrooks08 Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     
    There's no way to just have multiple .cpp files and right click and run (or something of the sort)? I don't want to have to build the whole project, I just want to compile the individual file and run.
  • 2. července 2009 19:02Nishant SivakumarModerátorUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     
    As far as I know, VS needs a project to build and run - it cannot handle standalone cpp files.
    http://blog.voidnish.com
  • 2. července 2009 19:40Brian MuthMVPUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Odpovědět
    There's no way to just have multiple .cpp files and right click and run (or something of the sort)? I don't want to have to build the whole project, I just want to compile the individual file and run.

    Just create a separate project for each .cpp file. You can have multiple projects in the same solution, which is very convenient.
  • 2. července 2009 20:02nobugzMVP, ModerátorUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Odpovědět
    Click, then Shift + Click to select all the files.  Right-click, Properties, General, set Excluded from Build = Yes.  Whatever file you want to try, set it back to No and build.  Avoid this problem in the future by keeping your main() in a separate source file.

    Hans Passant.