title: Segmentation Fault (core dumped) C++
body: <p>After researching I do believe I understand what the <code>&quot;Segmentation fault&quot;</code> error is. However, even after commenting out the code line by line, I can not seem to find where the fault is occurring in order to fix it.  Is there something I am overlooking that is causing this error? Below is what shows up when I run the code:</p>
  <blockquote>
  <p>Ready to play (y/n)? y</p>
  <p>3C AH 4C 3H 4H 2H 5H 2C 5C AC</p>
  <p>Here's your cards: 3C AH 4C 3H 4H</p>
  <p>Segmentation fault (core dumped)</p>
  </blockquote>
  <p>Pasted below is the code that I am referring to. The commented out parts were just me trying to find where the error was occurring:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;sstream&gt;
  #include &lt;ctime&gt;
  #include &lt;cstdlib&gt;
  #include &lt;string&gt;
  #include &lt;cstring&gt;
  #include &lt;stdio.h&gt;
  using namespace std;
  
  vector&lt;string&gt; bigDeck;
  vector&lt;string&gt; cardDeck;
  vector&lt;string&gt; playerHand;
  vector&lt;string&gt; computerhand;
  vector&lt;string&gt; shortvec;
  
  const int DEAL_CARDS = 5;
  
  
  void ResetDeck();
  void Shuffle();
  void DealACard();
  void DealQCard();
  void DealBCard();
  string CStr(int);
  int letsee2;
  
  int main()
  {
  
  
  cout &lt;&lt; &quot;Ready to play (y/n)? &quot;;
  
  char yn;
  cin &gt;&gt; yn;
  if (yn == 'n' || yn != 'y') return 0;
  
  ResetDeck();
  
  srand(time(0));
  
  Shuffle();
  
  for (int f=0; f &lt; 10; f++)
  {
          cout &lt;&lt; cardDeck[f] &lt;&lt; &quot; &quot;;
  }
  
  
  cout &lt;&lt; &quot;\n\nHere's your cards: &quot;;
  for (int i=0; i &lt; DEAL_CARDS; i++)
  {
          DealACard();
          cout &lt;&lt; playerHand[i] &lt;&lt; &quot; &quot;;
  }
  
  cout&lt;&lt;&quot;\n\nHere's the Computer's cards: &quot;;
  for (int k=0; k &lt; DEAL_CARDS; k++)
  {
          DealBCard();
          cout &lt;&lt; computerhand[k] &lt;&lt; &quot; &quot;;
  }
  
  for (int u=0; u &lt; DEAL_CARDS; u++)
  {
          DealQCard();
  }
  
  cout&lt;&lt;shortvec.size()&lt;&lt;endl;
  
  cout&lt;&lt;endl&lt;&lt;endl;
  
  //do
  //{
  
  for (int woh=0; woh &lt; DEAL_CARDS; woh++)
  {
   if ((playerHand[woh][0]=='A') &amp;&amp; (computerhand[woh][0]=='A'))
          {
                  cout&lt;&lt;&quot;War!&quot;&lt;&lt;endl;
  
  
          }
          else if ((playerHand[woh][0]=='A') &amp;&amp; (computerhand[woh][0]!='A'))
          {
                  cout&lt;&lt;&quot;Player wins&quot;&lt;&lt;endl;
                  /*playerHand.push_back(computerhand[woh]);
                  computerhand.erase(computerhand.begin()+(woh-1));*/
          }
          else if ((playerHand[woh][0]!='A') &amp;&amp; (computerhand[woh][0]=='A'))
          {
                  cout&lt;&lt;&quot;Computer Wins&quot;&lt;&lt;endl;
                  /*computerhand.push_baci(playerHand[woh]);
                  playerHand.erase(playerHand.begin()+(woh-1));*/
          }
          else
          {
                  if ((atoi(playerHand[woh].c_str())) &gt; (atoi(computerhand[woh].c_str())))
                  {
                          cout&lt;&lt;&quot;Player wins!&quot;&lt;&lt;endl;
                          /*playerHand.push_back(computerhand[woh]);
                          computerhand.erase(computerhand.begin()+(woh-1));*/
                  }
                  else if ((atoi(playerHand[woh].c_str())) &lt; (atoi(computerhand[woh].c_str())))
                  {
                          cout&lt;&lt;&quot;Computer wins!&quot;&lt;&lt;endl;
                          /*computerhand.push_back(playerHand[woh]);
                          playerHand.erase(playerHand.begin()+(woh-1));*/
                  }
                  else
                  {
                          cout&lt;&lt;&quot;War!&quot;&lt;&lt;endl;
  
                  }
          }
  /*if (playerHand.size() &gt; computerhand.size())
          shortvec = computerhand;
  else
          shortvec = playerHand;
  
  cout&lt;&lt;endl&lt;&lt;endl;
  */
  }
  /*for (int z=0; z &lt; playerHand.size(); z++)
  {
          cout &lt;&lt; playerHand[z] &lt;&lt; &quot; &quot;;
  }
  
  cout&lt;&lt;&quot;\n\nHere's the Computer's cards: &quot;;
  for (int y=0; y &lt; computerhand.size(); y++)
  {
          cout &lt;&lt; computerhand[y] &lt;&lt; &quot; &quot;;
  }*/
  
  cout&lt;&lt;endl&lt;&lt;endl;
  //}
  //while(((playerHand.size())!=10) || (computerhand.size())!=10);
  
  return 0;
  }
  void Shuffle()
  {
          random_shuffle(cardDeck.begin(),cardDeck.end());
  }
  
  void DealBCard()
  {
          computerhand.push_back(cardDeck[0]);
          cardDeck.erase(cardDeck.begin());
  }
  
  void DealACard()
  {
          playerHand.push_back(cardDeck[0]);
          cardDeck.erase(cardDeck.begin());
  }
  
  void DealQCard()
  {
          shortvec.push_back(bigDeck[0]);
          bigDeck.erase(bigDeck.begin());
  }
  
  string CStr(int n)
  {
          stringstream s;
          s &lt;&lt; n;
          return s.str();
  }
  
  void ResetDeck()
  {
          cardDeck.clear();
          playerHand.clear();
          computerhand.clear();
  
          for (int i=2; i&lt;6; ++i)
          {
                  cardDeck.push_back(CStr(i) + &quot;H&quot;);
                  cardDeck.push_back(CStr(i) + &quot;C&quot;);
          }
          cardDeck.push_back(&quot;AH&quot;);
          cardDeck.push_back(&quot;AC&quot;);
  }
  </code></pre>