Fazer uma PerguntaFazer uma Pergunta
 

RespondidoSimple Answer for Simple Question

  • quinta-feira, 2 de julho de 2009 18:47cmbrooks08 Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    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?

Respostas

  • quinta-feira, 2 de julho de 2009 19:40Brian MuthMVPMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    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.
  • quinta-feira, 2 de julho de 2009 20:02nobugzMVP, ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    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.

Todas as Respostas

  • quinta-feira, 2 de julho de 2009 18:54Nishant SivakumarModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    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
  • quinta-feira, 2 de julho de 2009 18:58cmbrooks08 Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    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.
  • quinta-feira, 2 de julho de 2009 19:02Nishant SivakumarModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    As far as I know, VS needs a project to build and run - it cannot handle standalone cpp files.
    http://blog.voidnish.com
  • quinta-feira, 2 de julho de 2009 19:40Brian MuthMVPMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    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.
  • quinta-feira, 2 de julho de 2009 20:02nobugzMVP, ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    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.