title: How to log variable value changes to a CSV file during debug in Visual Studio 2015 C++ Project?
body: <p>I am working on a war game project using legacy C++ code. Attacks appear to be functioning strangely in "extreme cases" (e.g., a combat in one game "tile" in which 5000 arrows are fired at a group of 3 regiments, one of which can be the target for any of the ~5000 potential "hits" in the course of one game turn). My task is to collate data on what is happening during a game turn.</p>
  
  <p>I need to record how the value for one particular Local variable changes during the course of one game turn for any unit that comes under fire (restricting to a 'test scenario' in which only regiments in one tile are under attack).</p>
  
  <p>My Visual Studio "Watch window" at the beginning of a debug session looks about like this:</p>
  
  <pre><code>Name----------------------Value------------Type
  targ-----------------------011-------------short
  (gUnit[011]).damage--------0---------------short
  (gUnit[047]).damage--------0---------------short
  (gUnit[256]).damage--------0---------------short
  </code></pre>
  
  <p>What this mean is: at the first breakpoint, the regiment represented in nested array gUnit[011]) has been determined to be the target ("targ") for a "hit" and the "damage" for that regiment prior to this hit is = 0.</p>
  
  <p>After one loop that may change to this:</p>
  
  <pre><code>Name----------------------Value------------Type
  targ-----------------------256-------------short
  (gUnit[011]).damage--------3---------------short
  (gUnit[047]).damage--------0---------------short
  (gUnit[256]).damage--------0---------------short
  </code></pre>
  
  <p>Which means: after one "hit" Regiment 011 has suffered 3 damage, and now for the next hit that has been determined to occur Regiment 047 is the target. So for each cycle of the call loop, any of the potential targets can be reassigned as the target and the value of 'damage' can change. For this example of 5000 arrows fired, there could be 5000 hits (though it would be unlikely to be > 1300 hits for that many shots fired). For each hit that occurs in the span of one game turn, I need to record:
  target and damage</p>
  
  <p>I have breakpoints setup and I can do what I need to do <em>manually</em> meaning:</p>
  
  <ol>
  <li><p>Advance to first call to the function that determines a hit ["MissileHit()"]</p></li>
  <li><p>Advance again and note that value for (gUnit[011]).damage has changed from 0 to 3. /* i.e., the Regiment with the ID "011" has taken "3" damage . . . */</p></li>
  <li><p>Repeat 5000 times for experiment ONE (and noting that, with each loop targ can change to any of the three arrays that represent the units that are under attack in the tile.</p></li>
  <li><p>Repeat for another 7 experiments (with slightly different conditions) for phase one of testing.</p></li>
  <li><p>Repeat for perhaps 3 or 4 more phases of testing . . .</p></li>
  </ol>
  
  <p>In sum, THOUSANDS of rows with at least two columns:
  targ.......damage</p>
  
  <p>(as a side note, this csv will get additional columns plugged in to it after each test cycle, so the final spreadsheet will look more like this:
  atkrID....Terrain....atkrExpr....atkrFatig....targID....targDamage</p>
  
  <p>The end result of all this data collection being: descriptive statistics can be calculated on the various in-game variables that mediate the outcomes of attacks)</p>
  
  <p>Obviously, doing this "manually" would be ridiculous.</p>
  
  <p>Is there an easy way to get Visual Studio to generate csv files that will record this data for me?</p>
  
  <p>I can certainly go down the path of writing scripts to run when these breakpoints execute, and fstreaming stuff into a file. But, I'm still wet-behind the ears (both with Visual Studio, C++ and developing in general!) so, I thought it worth asking if there are built in features of Visual Studio that would facilitate this.</p>