title: Casting from `int` to `unsigned char`
body: <p>I am running the following C++ code on <a href="http://coliru.stacked-crooked.com/" rel="noreferrer">Coliru</a>:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  int main()
  {
       int num1 = 208;
       unsigned char uc_num1 = (unsigned char) num1;
       std::cout &lt;&lt; "test1: " &lt;&lt; uc_num1 &lt;&lt; "\n";
  
       int num2 = 255;
       unsigned char uc_num2 = (unsigned char) num2;
       std::cout &lt;&lt; "test2: " &lt;&lt; uc_num2 &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>I am getting the output:</p>
  
  <pre><code>test1: �
  
  test2: �
  </code></pre>
  
  <p>This is a simplified example of my code.</p>
  
  <p>Why does this not print out:</p>
  
  <pre><code>test1: 208
  
  test2: 255
  </code></pre>
  
  <p>Am I misusing <code>std::cout</code>, or am I not doing the casting correctly?</p>
  
  <hr>
  
  <p><strong>More background</strong></p>
  
  <p>I want to convert from <code>int</code> to <code>unsigned char</code> (rather than <code>unsigned char*</code>). I know that all my integers will be between 0 and 255 because I am using them in the RGBA color model.</p>
  
  <p>I want to use <a href="http://lodev.org/lodepng/" rel="noreferrer">LodePNG</a> to encode images. The library in <code>example_encode.cpp</code> uses <code>unsigned char</code>s in <code>std::vector&lt;unsigned char&gt;&amp; image</code>:</p>
  
  <pre><code>//Example 1
  //Encode from raw pixels to disk with a single function call
  //The image argument has width * height RGBA pixels or width * height * 4 bytes
  void encodeOneStep(const char* filename, std::vector&lt;unsigned char&gt;&amp; image, unsigned width, unsigned height)
  {
    //Encode the image
    unsigned error = lodepng::encode(filename, image, width, height);
  
    //if there's an error, display it
    if(error) std::cout &lt;&lt; "encoder error " &lt;&lt; error &lt;&lt; ": "&lt;&lt; lodepng_error_text(error) &lt;&lt; std::endl;
  }
  </code></pre>