SERVING THE QUANTITATIVE FINANCE COMMUNITY

 
User avatar
Alan
Topic Author
Posts: 9787
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

Basic usage -- Visual Studio

January 24th, 2015, 5:03 pm

I hardly ever use Visual Studio, so here is a basic "how to" question. I have a C/C++ console project consisting of two .cpp files, one with the main entry point, call it main.cppNow, it comes up all the time that I want to try a new method/approach in the main.cppSo I want to basically save that and start again with a new version main2.cpp, keeping everything else the same.What is the *easiest* way to do this?If it matters I am using VS 2013 Community edition
 
User avatar
pcaspers
Posts: 688
Joined: June 6th, 2005, 9:49 am

Basic usage -- Visual Studio

January 24th, 2015, 5:19 pm

I find it useful to use argv[1] to choose the sub program to invoke. With that you have always all alternatives available without recompiling.
 
User avatar
Polter
Posts: 2526
Joined: April 29th, 2008, 4:55 pm

Basic usage -- Visual Studio

January 24th, 2015, 7:02 pm

One solution -- two separate projects.Afterward, simply use "Set as StartUp Project" -- personally, I've set up a keyboard shortcut for this option; something along these lines:http://stackoverflow.com/a/2837310http: ... p-project/
 
User avatar
Cuchulainn
Posts: 59713
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Basic usage -- Visual Studio

January 24th, 2015, 7:22 pm

A design solution is some kind of Factory pattern. You were not specific but I use it to have 1 main.cpp let's say for all kinds of PDE;1. BS vs CEV vs CIR2. Domain truncation vs domain transformation3. Initialise option data.4. FDM of all shapes and coloursIs your concern one of configuration and reducing complexity? Or something else? Do you get duplicate code and lots of if elses? Can you show a snippet of code?
Last edited by Cuchulainn on January 23rd, 2015, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 59713
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Basic usage -- Visual Studio

January 24th, 2015, 7:30 pm

QuoteOriginally posted by: pcaspersI find it useful to use argv[1] to choose the sub program to invoke. With that you have always all alternatives available without recompiling.Indeed. This determines which factory/method to use. So you only need 1 main() and 1 project in principle. For more complex object networks you need argv[2] etc.?
Last edited by Cuchulainn on January 23rd, 2015, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 59713
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Basic usage -- Visual Studio

January 24th, 2015, 7:33 pm

QuoteOriginally posted by: PolterOne solution -- two separate projects.Afterward, simply use "Set as StartUp Project" -- personally, I've set up a keyboard shortcut for this option; something along these lines:http://stackoverflow.com/a/2837310http: ... roject/For prototyping?I use 1 Project with multiple main(), only one of which is not excluded from a Build. I still get duplicate code.
 
User avatar
Cuchulainn
Posts: 59713
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Basic usage -- Visual Studio

January 24th, 2015, 8:13 pm

yep, that's it. The fun starts when the nested if elses arise, e.g. a methods parameters can be generated in different ways, i.e. multiple levels of indirection.
Last edited by Cuchulainn on January 23rd, 2015, 11:00 pm, edited 1 time in total.
 
User avatar
pcaspers
Posts: 688
Joined: June 6th, 2005, 9:49 am

Basic usage -- Visual Studio

January 24th, 2015, 8:30 pm

QuoteOriginally posted by: outrunhere is an argv exampleyes that's how I meant it.
 
User avatar
Alan
Topic Author
Posts: 9787
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

Basic usage -- Visual Studio

January 25th, 2015, 2:03 pm

Thanks, guys for the various suggestions. I think for my current purposes, Polter's "one solution, 2 projects" suggestion fits best.So, I just created essentially a copy of my current project in my current solution.To do this, I -added a new project to the solution.-selected, copied, and pasted my current main1.cpp code into the new main2.cpp file. -added the other file.cpp I am using to the project as an existing item.-had to go into project properties to make a command line addition I am using.So, in the context of one solution/two projects, my question becomes: is there any easier way to do all this?I simply want the new project to begin in a state in which (i) the new main.cpp file is a duplicate of the old one,(ii) all the other files are added as existing items, and (iii) all the command line settings are the same. Maybe I am spoiled from Mathematica. There, to start afresh, I would simply save the notebook under a new name andbe off and running.
Last edited by Alan on January 24th, 2015, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 59713
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Basic usage -- Visual Studio

January 25th, 2015, 5:30 pm

MSDN in google is good as wellVS. An important observation is the VS supports Common Solution Propertieshttps://msdn.microsoft.com/en-us/library/vstudio/1skczxch(v=vs.100).aspx
Last edited by Cuchulainn on January 24th, 2015, 11:00 pm, edited 1 time in total.
 
User avatar
Alan
Topic Author
Posts: 9787
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

Basic usage -- Visual Studio

January 25th, 2015, 7:08 pm

Following Daniel's suggestion, just I looked at the Common Properties dialog to see if there was a way of making my Command Line edit a common property, but didn't find that. So, I guess I will always have to do that manually in any new project. No big deal on that one.As far I can see, the solution is essentially outrun's: -create the new project-outside of VS: copy the previous main.cpp file into the new project's folder-back in VS: add the copied file as an existing item. Seems kludgy to me to have to leave VS to do such a common task, but unless I hear otherwise, I guess that's it and my issue is resolved.Thanks again to all who responded.
Last edited by Alan on January 24th, 2015, 11:00 pm, edited 1 time in total.
 
User avatar
robert2098
Posts: 26
Joined: July 21st, 2004, 6:44 am

Basic usage -- Visual Studio

January 27th, 2015, 8:58 am

QuoteOriginally posted by: AlanI hardly ever use Visual Studio, so here is a basic "how to" question. I have a C/C++ console project consisting of two .cpp files, one with the main entry point, call it main.cppNow, it comes up all the time that I want to try a new method/approach in the main.cppSo I want to basically save that and start again with a new version main2.cpp, keeping everything else the same.What is the *easiest* way to do this?If it matters I am using VS 2013 Community editionIf your source files are in the project directory, one way is to have multiple mainX.cpp files and exclude the unused ones from your project and make the solution explorer show all files.First make the solution explorer show all files:Tools -> Options -> Projects and Solutions -> VC++ Project Settings -> Solution Explorer ModeThis option will set the solution explorer to show all files by default but the solution explorer view can be toggled between project view/all files view using the "two page" icon on top of the solution explorer.Now select the file you want to exclude in the solution explorer. In the properties Window set the "Included in project" option to false. The file in the solution explorer will now have a stop sign in the icon. This way you can "toggle" the main files you want to include or not. Create new mainX.cpp files by adding a new cpp file to the project and then copy and pasting the required code from another mainX.cpp file.A more advanced option might be to use unit test projects where you can turn your multiple main functions into test functions and run them at will. Put all your regular code in a static library project. Then add a "Visual C++ Native Unit Test" project that references the static library project. Then instead of writing a main() function, write multiple test classes or multiple test functions in a single test class. Then use the "TEST -> Windows -> Test Explorer" to open test explorer window. In the Window you see all the test methods (which are your formerly main methods) you wrote. Right click the test you want to run and select run. You can also create playlists to run a selection of tests or run all your test functions. Your tests need the "Logger::WriteMessage()" to write output the Visual Studio's output Window. No console window is available.It is not needed to create a separate test project but the test functions can also be added to your main project after you added the unit test header and lib files to the project.For more information about unit testing see: https://msdn.microsoft.com/en-us/librar ... aspxRobert
Last edited by robert2098 on January 27th, 2015, 11:00 pm, edited 1 time in total.
 
User avatar
Alan
Topic Author
Posts: 9787
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

Basic usage -- Visual Studio

January 27th, 2015, 2:49 pm

Thanks, Robert -- both good suggestions. I'm at Ver2 of my code now but when I want to try a Ver3, I'll try your first idea. BTW, there's a separate button for posting https
Last edited by Alan on January 26th, 2015, 11:00 pm, edited 1 time in total.
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On