title: How to measure the correct size of non-ASCII characters?
body: <p>In the following program, I'm trying to measure the length of a string with non-ASCII characters.</p>
  
  <p>But, I'm not sure why the <code>size()</code> doesn't print the correct length when using non-ASCII characters.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  int main()
  {
      std::string s1 = "Hello";
      std::string s2 = "इंडिया"; // non-ASCII string
      std::cout &lt;&lt; "Size of " &lt;&lt; s1 &lt;&lt; " is " &lt;&lt; s1.size() &lt;&lt; std::endl;
      std::cout &lt;&lt; "Size of " &lt;&lt; s2 &lt;&lt; " is " &lt;&lt; s2.size() &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Size of Hello is 5
  Size of इंडिया is 18
  </code></pre>
  
  <p>Live demo <a href="https://wandbox.org/permlink/UWkoIQdNACFI8I78" rel="nofollow noreferrer">Wandbox</a>.</p>