title: C++ How to get first letter of wstring
body: <p>This sounds like a simple problem, but C++ is making it difficult (for me at least): I have a wstring and I would like to get the first letter as a wchar_t object and then remove this first letter from the string.</p>
  
  <p>This here does not work for non-ASCII characters: </p>
  
  <pre><code>wchar_t currentLetter = word.at(0);  
  </code></pre>
  
  <p>Because it returns two characters (in a loop) for characters such as German Umlauts. </p>
  
  <p>This here does not work, either: </p>
  
  <pre><code>wchar_t currentLetter = word.substr(0,1);
  
  error: no viable conversion from 'std::basic_string&lt;wchar_t&gt;' to 'wchar_t'
  </code></pre>
  
  <p>And neither does this: </p>
  
  <pre><code>wchar_t currentLetter = word.substr(0,1).c_str();
  
  error: cannot initialize a variable of type 'wchar_t' with an rvalue of type 'const wchar_t *'
  </code></pre>
  
  <p>Any other ideas? </p>
  
  <p>Cheers, </p>
  
  <p>Martin </p>
  
  <p>---- Update -----
  Here is some executable code that should demonstrate the problem. This program will loop over all letters and output them one by one: </p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main() {
      wstring word = L"für";
      wcout &lt;&lt; word &lt;&lt; endl;
      wcout &lt;&lt; word.at(1) &lt;&lt; " " &lt;&lt; word[1] &lt;&lt; " " &lt;&lt; word.substr(1,1) &lt;&lt; endl;
  
      wchar_t currentLetter;
      bool isLastLetter;
  
      do {
          isLastLetter = ( word.length() == 1 );
          currentLetter = word.at(0);
          wcout &lt;&lt; L"Letter: " &lt;&lt; currentLetter &lt;&lt; endl;
  
          word = word.substr(1, word.length()); // remove first letter
      } while (word.length() &gt; 0);
  
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>However, the actual output I get is: </p>
  
  <p>f?r
  ? ? ?
  Letter: f
  Letter: ?
  Letter: r</p>
  
  <p>The source file is encoded in UTF8 and the console's encoding is also set to UTF8. </p>