2010-01-30 10 views

risposta

3
#include <iostream> 
#include <locale> 
#include <string> 

int main() 
{ 
     using namespace std; 
     wstring wcs = L"中文"; 
     locale old = wcout.imbue(locale("")); // "" is environment's default locale 
     wcout<<wcs<<endl; 
     wcout.imbue(old);      // restore old locale 
} 
+0

Non risponde alla domanda: questo scrive caratteri completamente diversi: P – Thomas

+1

@Thomas: Ma a meno che tu non sia completamente cerebralmente morto (che spero non sia vero per tutti i programmatori). La possibilità di cambiare il programma di cui sopra per stampare diversi personaggi sarà (come dovrei dirlo) "Un troncone morto e incolla". L'intero punto è impostare il locale corretto (poiché l'impostazione predefinita è la localizzazione "C", che di solito non è molto buona se non in inglese). –

+1

Non dimenticare di usare un font che contenga le lettere della lingua desiderata. Inoltre, il farsi come l'arabo è RTL, alcune lettere sono collegate e altre no. Buona fortuna cercando di "aggiustare" la stupida console di vittoria per fare quello che vuoi;) – AraK

3

È necessario convertire la stringa in una codepage corretta. Le codepage MS-DOS sono denominate CP437, con CP seguito da tre cifre. Si noti che normalmente possono essere visualizzati solo meno di 256 caratteri diversi e quindi molti caratteri Unicode non possono essere visualizzati in modalità testo.

+0

CP708 è la tabella codici araba in MS-DOS. Vedere http://msdn.microsoft.com/en-us/library/cc195051.aspx per l'elenco completo da Microsoft. – David

0

è possibile utilizzare wchar_t anziché char.

e dovresti usare anche wcout invece di cout.

se la console supporta unicode funzionerà. un altro modo per gli iraniani era un software chiamato "vegaf", ma è stato per molti anni fa e io lo dimentico.

0
using namespace std; 
setlocale(LC_ALL, "fa-IR"); 

time_t rawtime; 
struct tm * timeinfo; 

time(&rawtime); 
timeinfo = localtime(&rawtime); 

struct lconv * lc; 
lc = localeconv(); 


LOGFONT * tFont; 
tFont = GetFont(); 

CFont font; 
VERIFY(font.CreateFont(
    tFont->lfHeight,     // nHeight 
    tFont->lfWidth,      // nWidth 
    0,         // nEscapement 
    0,         // nOrientation 
    tFont->lfWeight,     // nWeight 
    FALSE,        // bItalic 
    FALSE,        // bUnderline 
    0,         // cStrikeOut 
    ARABIC_CHARSET,      // nCharSet 
    OUT_DEFAULT_PRECIS,     // nOutPrecision 
    CLIP_DEFAULT_PRECIS,    // nClipPrecision 
    ANTIALIASED_QUALITY,    // nQuality 
    DEFAULT_PITCH | FF_SWISS,   // nPitchAndFamily 
    tFont->lfFaceName));   // lpszFacename 

const wchar_t yek = L'\u06F1'; 
const wchar_t dow = L'\u06F2'; 
const wchar_t seh = L'\u06F3'; 
const wchar_t chahar = L'\u06F4'; 
const wchar_t panj = L'\u06F5'; 
const wchar_t shish = L'\u06F6'; 
const wchar_t haft = L'\u06F7'; 
const wchar_t hasht = L'\u06F8'; 
const wchar_t noh = L'\u06F9'; 
const wchar_t sefr = L'\u06F0'; 

wchar_t wFATime[20]; 
wcscpy(wFATime, L""); 

BOOL dayoftheweek = FALSE; 
for (unsigned int i = 0; i<m_strText.GetLength(); i++) 
{ 
    char c = m_strText[i]; //this is your character 


    switch (c) 
    { 
    case '1': 
     wcsncat(wFATime, &yek, 1); 
     break; 
    case '2': 
     wcsncat(wFATime, &dow, 1); 
     break; 
    case '3': 
     wcsncat(wFATime, &seh, 1); 
     break; 
    case '4': 
     wcsncat(wFATime, &chahar, 1); 
     break; 
    case '5': 
     wcsncat(wFATime, &panj, 1); 
     break; 
    case '6': 
     wcsncat(wFATime, &shish, 1); 
     break; 
    case '7': 
     wcsncat(wFATime, &haft, 1); 
     break; 
    case '8': 
     wcsncat(wFATime, &hasht, 1); 
     break; 
    case '9': 
     wcsncat(wFATime, &noh, 1); 
     break; 
    case '0': 
     wcsncat(wFATime, &sefr, 1); 
     break; 
    case ':': 
     wcsncat(wFATime, L":", 1); 
     break; 
    case '.': 
     wcsncat(wFATime, L".", 1); 
     break; 
    case '/': 
     wcsncat(wFATime, L"/", 1); 
     break; 
    default: 
     dayoftheweek = TRUE; 
    } 
} 

CFont* def_font = pdc->SelectObject(&font); 
HDC hdc = pdc->GetSafeHdc(); 

int old = pdc->SetBkMode(TRANSPARENT); 
if (dayoftheweek) 
{ 
    CStringW strw(m_strText); 
    ::TextOutW(hdc, m_poOffset.x, m_poOffset.y, strw, strw.GetLength()); 
} 
else 
{ 
    ::TextOutW(hdc, m_poOffset.x, m_poOffset.y, wFATime, wcslen(wFATime)); 
} 



pdc->SelectObject(def_font); 
pdc->SetBkMode(old); 
// Done with the font. Delete the font object. 
font.DeleteObject(); 
Problemi correlati