title: Jump bypasses variable initialization in switch statement
body: <p>I need an <code>std:: vector&lt;char&gt;</code> or an <code>std:: string</code> in my switch case for some purpose. So, I wrote the following dummy code to see if it works:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  int main() {
      int choice = 0;
  
      do {
          std:: cout &lt;&lt; "Enter Choice" &lt;&lt; std::endl;
          std:: cin &gt;&gt; choice;
  
          switch(choice) {
              case 1:
                  std::cout &lt;&lt; "Hi";
                  break;
  
              case 2:
                  std::string str;
                  std::cin &gt;&gt; str;
                  break;
  
              case 3: //Compilation error, Cannot jump from switch statement to this case label
                  std::cout &lt;&lt; "World" &lt;&lt; std:: endl;
                  break;
  
              default:
                  std:: cout &lt;&lt; "Whatever" &lt;&lt; std:: endl;
          }
  
      } while(choice != 5);
      return 0;
  }
  </code></pre>
  
  <p>Ok, I somewhat got it that <code>str</code> is an object of <code>std:: string</code> type. So, I am trying to jump through this variable initialization. </p>
  
  <p>Then why a definition of C style string does not cause compilation error:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  int main() {
      int choice = 0;
  
      do {
          std:: cout &lt;&lt; "Enter Choice" &lt;&lt; std::endl;
          std:: cin &gt;&gt; choice;
  
          switch(choice) {
              case 1:
                  std::cout &lt;&lt; "Hi";
                  break;
  
              case 2:
                  char str[6];
                  std::cin &gt;&gt; str;
                  break;
  
              case 3:
                  std::cout &lt;&lt; "World" &lt;&lt; std:: endl;
                  break;
  
              default:
                  std:: cout &lt;&lt; "Whatever" &lt;&lt; std:: endl;
          }
  
      } while(choice != 5);
      return 0;
  }
  </code></pre>
  
  <p>How can I make the first code to work?</p>