title: Visual Studio C++ Exception thrown: read access violation. When debugging using Command Line Argument
body: <p>I am receiving an error exception thrown when executing the following code using c++ in Visual Studio 2015 Community on Windows 10 and I do not know how to fix it even after exhausting numerous searches for anyone with the same problem.  Visual Studio 2015 Community was working properly for a long time now on this computer running Windows 10 but just this past week it has been giving me issues when debugging any c++ program; specifically a program requiring use of a command line argument.  This code demonstrates the problem and if anyone could point me in the right direction as to how to fix it please let me know.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main(int argc, char *argv[])
  {
      cout &lt;&lt; "program name : " &lt;&lt; argv[0] &lt;&lt; endl;
      cout &lt;&lt; "first command argument : " &lt;&lt; argv[1] &lt;&lt; endl;
  
      cin.get();
      return 0;
  }
  </code></pre>
  
  <p>I am adding a command line argument by <a href="http://i.stack.imgur.com/l4sT6.png" rel="nofollow">entering it into the debugging properties window</a>.  If I run the program with ctrl + F5, it just hangs and prompts a screen that the program has stopped working.  Then upon running the program with F5, I receive <a href="http://i.stack.imgur.com/Fpb5j.png" rel="nofollow">this error message</a> of </p>
  
  <p>"Exception thrown: read access violation.</p>
  
  <p>_First was nullptr.</p>
  
  <p>If there is a handler for this exception, the program may be safely continued."</p>
  
  <p>Visual Studio points to where the exception was thrown which is a file iosfwd located inside the c:\Program Files (x86)\Visual Studio 14\VC\include\ folder.  The block that it specifically points to is inside the struct char_traits and the function with the exception thrown pointing to the return line:</p>
  
  <pre><code>static size_t __CLRCALL_OR_CDECL length(const _Elem *_First)
      {   // find length of null-terminated string
      return (*_First == 0 ? 0
          : _CSTD strlen(_First));
      }
  </code></pre>
  
  <p>At the time of the error being thrown the console output window hangs at "first command argument : " and does not display "hi". It does however correctly output the file location of the program name as specified in argv[0].</p>
  
  <p>If I run the Project1.exe from my command prompt it runs as intended and will output the command line argument added when entered in line.  This tells me that there is an issue with Visual Studio and not with my code.  I would appreciate any help as how to solve this problem as I prefer using Visual Studio for writing c++.  Thanks.</p>