title: Correctly reading a utf-16 text file into a string without external libraries?
body: <p>I've been using StackOverflow since the beginning, and have on occasion been tempted to post questions, but I've always either figured them out myself or found answers posted eventually... until now. This <em>feels</em> like it should be fairly simple, but I've been wandering around the internet for hours with no success, so I turn here:</p>
  
  <p>I have a pretty standard utf-16 text file, with a mixture of English and Chinese characters. I would like those characters to end up in a string (technically, a wstring). I've seen a lot of <em>related</em> questions answered (here and elsewhere), but they're either looking to solve the much harder problem of reading arbitrary files without knowing the encoding, or converting between encodings, or are just generally confused about "Unicode" being a range of encodings. I know the source of the text file I'm trying to read, it will always be UTF16, it has a BOM and everything, and it can stay that way. </p>
  
  <p>I had been using the solution described <a href="http://cfc.kizzx2.com/index.php/reading-a-unicode-utf16-file-in-windows-c">here</a>, which worked for text files that were all English, but after encountering certain characters, it stopped reading the file. The only other suggestion I found was to use <a href="http://site.icu-project.org/">ICU</a>, which would probably work, but I'd really rather not include a whole large library in an application for distribution, just to read one text file in one place. I don't care about system independence, though - I only need it to compile and work in Windows. A solution that didn't rely on that fact would <em>prettier</em>, of course, but I would be just as happy for a solution that used the stl while relying on assumptions about Windows architecture, or even solutions that involved win32 functions, or ATL; I just don't want to have to include another large 3rd-party library like ICU. Am I still totally out of luck unless I want to reimplement it all myself?</p>
  
  <p>edit: I'm stuck using VS2008 for this particular project, so C++11 code sadly won't help.</p>
  
  <p>edit 2: I realized that the <a href="http://cfc.kizzx2.com/index.php/reading-a-unicode-utf16-file-in-windows-c">code</a> I had been borrowing before didn't fail on non-English characters like I thought it was doing. Rather, it fails on specific characters in my test document, among them '：' (FULLWIDTH COLON, U+FF1A) and '）' (FULLWIDTH RIGHT PARENTHESIS, U+FF09). bames53's posted solution also mostly works, but is stumped by those same characters?</p>
  
  <p>edit 3 (and the answer!): the original code I had been using -did- mostly work - as bames53 helped me discover, the ifstream just needed to be opened in binary mode for it to work.</p>