title: c++ cout string not working. Please advise
body: <p>I have the below code but for some reason the very last instance (where the noSpaces string should print out) is not being output for whatever reason. </p>
  
  <p>I've already verified that the entire program (excluding that one output string) is working perfectly.</p>
  
  <p><em>Note: I am speaking about the line right about <code>return 0</code></em></p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int countChar(string str);
  void removeSpaces(string str);
  
  
  int main()
  {
      cout &lt;&lt; "Select a word: ";
      string selectedWord;
      getline(cin,selectedWord);
      cout &lt;&lt; "The number of characters in the word " &lt;&lt; selectedWord &lt;&lt; " is " &lt;&lt; countChar(selectedWord) &lt;&lt; endl;
  
      int i=0;
      int j=0;
      string noSpaces;
      while(selectedWord[i]!='\0') {
          if(selectedWord[i]!=' ') {
              noSpaces[j]=selectedWord[i];
              j++;
          }
          i++;
      }
      cout &lt;&lt; "The reverse of your selected word is: " &lt;&lt; noSpaces &lt;&lt; endl;
  
      return 0;
  }
  
  int countChar(string str)
  {
      int i=0;
      while(str[i]!='\0') {
          i++;
      }
      return i;
  }
  </code></pre>