title: C++ encode string to Unicode - ICU library
body: <p>I need to convert a bunch of bytes in ISO-2022-JP and ISO-2022-JP-2 (and other variations of ISO-2022) into Unicode.  I am trying to use ICU (<a href="http://userguide.icu-project.org/conversion/converters" rel="nofollow noreferrer">link text</a>), but the following code doesn't work.</p>
  
  <pre><code>std::string input = "\x1B\x28\x4A" "ABC\xA6\xA7";    //the first 3 chars are escape sequence to use JIS_X201 character set in GL/GR
  UErrorCode status = U_ZERO_ERROR;
  UConverter *conv;
  // set up the converter
  conv = ucnv_open("ISO-2022-JP", &amp;status);
  if (status != U_ZERO_ERROR) return false;   //couldn't find character set
  
  UChar * convDest = new UChar[2*input.length()]; //ucnv_toUChars will use up to 2*length
  
  // convert to Unicode
  int resultLen = (int)ucnv_toUChars(conv, convDest, 2*input.length(), input.c_str(), input.length(), &amp;status);
  </code></pre>
  
  <p>This doesn't work.  The result contains '?' charcters for anything I put in that was above ASCII.  The status has no error.  What am I doing wrong?</p>
  
  <p>On top of that I was having trouble compiling the library ver 4.4 as the MSVC 9 project  would not convert to MSVC 10 project.</p>
  
  <p>I am also aware of libiconv open source library.  I couldn't compile that one on windows.  If anyone has any advice on a different library, that's also welcome.</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT</strong>
  The escape sequence I originally used was wrong.  So now ICU takes the string, strips out the escape sequence - which is a step in the right direction.  But the result still contains '?' chars.</p>
  
  <p><strong>EDIT2</strong> The reason I couldn't convert to MSVC 10 project was because x64 platform wasn't installed (it isn't by default).  Alternatively I could open all the projects in text editor and remove all mention of x64 target.</p>