Microsoft Developer Network > 포럼 홈 > Visual C++ General > Simple Answer for Simple Question
질문하기질문하기
 

답변됨Simple Answer for Simple Question

  • 2009년 7월 2일 목요일 오후 6:47cmbrooks08 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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?

답변

  • 2009년 7월 2일 목요일 오후 7:40Brian MuthMVP사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    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.
  • 2009년 7월 2일 목요일 오후 8:02nobugzMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    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.

모든 응답

  • 2009년 7월 2일 목요일 오후 6:54Nishant Sivakumar중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    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
  • 2009년 7월 2일 목요일 오후 6:58cmbrooks08 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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.
  • 2009년 7월 2일 목요일 오후 7:02Nishant Sivakumar중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    As far as I know, VS needs a project to build and run - it cannot handle standalone cpp files.
    http://blog.voidnish.com
  • 2009년 7월 2일 목요일 오후 7:40Brian MuthMVP사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    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.
  • 2009년 7월 2일 목요일 오후 8:02nobugzMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    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.