2010-12-01 13 views

cevap

9

Temelde, şans dışında şunlardır: http://www.siao2.com/2007/01/03/1392379.aspx

+0

Hmm, ama Windows uygulamaları nasıl yazıyor? Microsoft) desteklenen bir kodlama değilse UTF-8 ile çalışır? –

+0

Windows kendi API'sı için UTF-16 kullanır, böylece herhangi bir UTF-8 metni, Windows API'sına geçmeden önce UTF-16'ya dönüştürülür. UTF-8'i iyi bir şekilde tanıyın –

+0

@Nemanja Uh? Peki, blog yazısı ne hakkında konuşuyor? –

1

MSDN Başına, bu "english_us.65001" adlı olacaktır. Ancak, kod sayfası 65001, Windows'ta biraz kesikli.

+2

Eğer m lütfen yorum Can "biraz lapa lapa" cevher? –

+0

@Let_Me_Be: Bunu daha iyi özetleyemiyorum http://www.google.com/search?q=site%3Ablogs.msdn.com+65001 – MSalters

+1

@MSalters Üzgünüm, ancak hiçbir şey bulamıyorum Hem güncel hem de detaylı. Okuduğum kısa blog gönderilerinden anladığım şey, Windows'un hiç UTF-8 desteği olmadığını (ki bu hiç bir anlam ifade etmiyor). –

10

adlı yerel ayarlar için iyi bir destek olmamasına rağmen, Visual Studio 2010, UTF-8 dönüşüm C++ 11 gerektirdiği yönleriyle dahil yapar: UCS2 için std::codecvt_utf8 ve UTF-16 için std::codecvt_utf8_utf16:

#include <fstream> 
#include <iostream> 
#include <string> 
#include <locale> 
#include <codecvt> 
void prepare_file() 
{ 
    // UTF-8 data 
    char utf8[] = {'\x7a',      // latin small letter 'z' U+007a 
        '\xe6','\xb0','\xb4',   // CJK ideograph "water" U+6c34 
        '\xf0','\x9d','\x84','\x8b'}; // musical sign segno U+1d10b 
    std::ofstream fout("text.txt"); 
    fout.write(utf8, sizeof utf8); 
} 
void test_file_utf16() 
{ 
    std::wifstream fin("text.txt"); 
    fin.imbue(std::locale(fin.getloc(), new std::codecvt_utf8_utf16<wchar_t>)); 
    std::cout << "Read from file using UTF-8/UTF-16 codecvt\n"; 
    for(wchar_t c; fin >> c;) 
     std::cout << std::hex << std::showbase << c << '\n'; 
} 
void test_file_ucs2() 
{ 
    std::wifstream fin("text.txt"); 
    fin.imbue(std::locale(fin.getloc(), new std::codecvt_utf8<wchar_t>)); 
    std::cout << "Read from file using UTF-8/UCS2 codecvt\n"; 
    for(wchar_t c; fin >> c;) 
     std::cout << std::hex << std::showbase << c << '\n'; 
} 
int main() 
{ 
    prepare_file(); 
    test_file_utf16(); 
    test_file_ucs2(); 
} 

bu çıkışlar, benim Visual Studio 2010 EE SP1

Read from file using UTF-8/UTF-16 codecvt 
0x7a 
0x6c34 
0xd834 
0xdd0b 
Read from file using UTF-8/UCS2 codecvt 
0x7a 
0x6c34 
0xd10b 
Press any key to continue . . . 
İlgili konular