Re: Is it difficult to read UTF-8 .txt in VC++?
- From: Sin Jeong-hun <typingcat@xxxxxxxxx>
- Date: Fri, 06 Jul 2007 18:19:12 -0700
On Jul 7, 3:58 am, David Wilkinson <no-re...@xxxxxxxxxxxx> wrote:
Sin Jeong-hun wrote:Thank you, I'll try that.
I want to read a line from a .txt file (which is saved in
Unicode(UTF-8) and show the string in a MessageBox.
With C#, it is very easy.
StreamReader sr=new StreamReader("c:\\a.txt",Encoding.UTF8);
string line=sr.ReadLine();
sr.close();
MessageBox.Show(line);
But with unmanaged Visual C++, I couldn't even find a simple example.
I tried to use wifstream.getline but it didn't read Asian characters
correctly.
I've searched for the news groups for an answer but I all I found was
that
I might have to buy a third party library just to do that.
Do I really need to buy a library just to read simple UTF-8 text file?
(Of course, in case I don't know how to create an equivalent library
myself)
If not, could you plelase tell me the VC++ equivalent code for the C#
code above?
Thank you.
Sin:
UTF-8 uses 8-bit chatracters, so you should use ifstream not wifstream.
Use MultiByteToWideChar to convert to UTF-16. If your app is ANSI
compiled (I hope not) then use WideCharToMultiByte() to get the local
code page.
--
David Wilkinson
Visual C++ MVP
.
- References:
- Is it difficult to read UTF-8 .txt in VC++?
- From: Sin Jeong-hun
- Re: Is it difficult to read UTF-8 .txt in VC++?
- From: David Wilkinson
- Is it difficult to read UTF-8 .txt in VC++?
- Prev by Date: Re: Add/Remove impossible ... code element read only
- Next by Date: Re: Is it difficult to read UTF-8 .txt in VC++?
- Previous by thread: Re: Is it difficult to read UTF-8 .txt in VC++?
- Next by thread: Re: Is it difficult to read UTF-8 .txt in VC++?
- Index(es):
Relevant Pages
|