title: How to debug and fix a runtime error like "Unhandled exception at 0x.... in ....exe: 0xC0000005: Access violation writing location 0x...."
body: <p>For a project of mine, I am writing a save file reader.
  In the latest build I am getting a runtime error <code>Unhandled exception at 0x00075256 in Final Assessment.exe: 0xC0000005: Access violation writing location 0xCCCCCCCC.</code></p>
  
  <p>How can I go on to identify and correct the source of this error?</p>
  
  <p>I believe the error happens when I create the ifstream object <code>saveFile()</code>, but I have been unable to find the exact source.</p>
  
  <pre><code>bool Game::load(){
      string data[9];
      ifstream saveFile("save.dat");
      int x = 0;
      if (saveFile.is_open()){
          while (!saveFile.eof()){
              getline(saveFile,data[x]);
              x++;
          }
          saveFile.close();
  
          string savePlayerName = data[0];
          int saveBaseHealth = stringToInt(data[1]);
          int saveHealth = stringToInt(data[2]);
          int saveKilled = stringToInt(data[3]);
          int saveMoney = stringToInt(data[4]);
  
          string saveWeaponName = data[5];;
          int saveAttack = stringToInt(data[6]);
  
          string saveArmorName = data[7];
          int saveDefense = stringToInt(data[8]);
  
          mainPlayer.setName(savePlayerName);
          mainPlayer.setBaseHealth(saveBaseHealth);
          mainPlayer.setHealth(saveHealth);
          mainPlayer.setEnemiesKilled(saveKilled);
          mainPlayer.setMoney(saveMoney);
  
          mainWeapon.setName(saveWeaponName);
          mainWeapon.setAttackPower(saveAttack);
  
          mainArmor.setName(saveArmorName);
          mainArmor.setDefense(saveDefense);
          return true;
      }
      else
      {
          return false;
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/x01kj.png" alt="Debug"></p>