Jag har skrivit ett program som skriver ut WCHAR datew[80]; Så här långt har jag kommit hittills: Använder du ett teckensnitt i konsollfönstret som innehåller kinesiska tecken?Kineska tecken
dagens datum på olika språk, men när jag
försöker skriva ut datumet med kinesiska tecken krashar programet.
Så här ser koden ut:
<code>
#include <iostream>
#include <locale>
#include <time.h>
using namespace std;
int main()
{
char date[81];
time_t currentTime;
struct tm* tmTime;
time(¤tTime);
tmTime = gmtime(¤tTime);
locale swedish("swedish");
locale::global(swedish);
strftime(date, 80, "%#x", tmTime);
cout << "Svenskt datum: \n";
cout << date << endl << endl;
locale norwegianBokmal("norwegian-bokmal");
locale::global(norwegianBokmal);
strftime(date, 80, "%#x", tmTime);
cout << "Norskt datum (Bokmal): \n";
cout << date << endl << endl;
locale norwegianNynorsk("norwegian-nynorsk");
locale::global(norwegianNynorsk);
strftime(date, 80, "%#x", tmTime);
cout << "Norskt datum (Nynorsk): \n";
cout << date << endl << endl;
locale finnish("finnish");
locale::global(finnish);
strftime(date, 80, "%#x", tmTime);
cout << "Finskt datum: \n";
cout << date << endl << endl;
locale danish("danish");
locale::global(danish);
strftime(date, 80, "%#x", tmTime);
cout << "Danskt datum: \n";
cout << date << endl << endl;
locale french("french");
locale::global(french);
strftime(date, 80, "%#x", tmTime);
cout << "Franskt datum: \n";
cout << date << endl << endl;
locale german("german");
locale::global(german);
strftime(date, 80, "%#x", tmTime);
cout << "Tyskt datum: \n";
cout << date << endl << endl;
/*
locale chineseSimplified("chinese-simplified");
locale::global(chineseSimplified);
strftime(date, 80, "%#x", tmTime);
cout << "Kinesiskt datum (förenklad): \n";
cout << date << endl << endl;
*/
return 0;
}
</code>Sv: Kineska tecken
wcsftime(datew, 80, "%#x", tmTime);
WCHAR = unicode. (widechar)Sv:Kineska tecken
<code>
#include <iostream>
#include <locale>
#include <time.h>
using namespace std;
int wmain(void)
{
wchar_t date[81];
time_t currentTime;
struct tm tmTime;
time(¤tTime);
gmtime_s(&tmTime, ¤tTime);
_wasctime_s(date, 80, &tmTime);
locale swedish("swedish");
locale::global(swedish);
wcsftime(date, 80, L"%#x", &tmTime);
wcout << "Svenskt datum: \n";
wcout << date << endl << endl;
locale norwegianBokmal("norwegian-bokmal");
locale::global(norwegianBokmal);
wcsftime(date, 80, L"%#x", &tmTime);
wcout << "Norskt datum (Bokmal): \n";
wcout << date << endl << endl;
locale norwegianNynorsk("norwegian-nynorsk");
locale::global(norwegianNynorsk);
wcsftime(date, 80, L"%#x", &tmTime);
wcout << "Norskt datum (Nynorsk): \n";
wcout << date << endl << endl;
locale finnish("finnish");
locale::global(finnish);
wcsftime(date, 80, L"%#x", &tmTime);
wcout << "Finskt datum: \n";
wcout << date << endl << endl;
locale danish("danish");
locale::global(danish);
wcsftime(date, 80, L"%#x", &tmTime);
wcout << "Danskt datum: \n";
wcout << date << endl << endl;
locale french("french");
locale::global(french);
wcsftime(date, 80, L"%#x", &tmTime);
wcout << "Franskt datum: \n";
wcout << date << endl << endl;
locale german("german");
locale::global(german);
wcsftime(date, 80, L"%#x", &tmTime);
wcout << "Tyskt datum: \n";
wcout << date << endl << endl;
locale chineseSimplified("chinese-simplified");
locale::global(chineseSimplified);
wcsftime(date, 80, L"%#x", &tmTime);
wcout << L"Kinesiskt datum (förenklad): \n";
wcout << date << endl << endl;
return 0;
}
</code>
På msdn2.microsoft.com hittade jag en del Unicode-funktioner.
Programet fungerar, men det visas inga kinesiska tecken.
Jag använder VC++ 2005 Express Edition, om det har någon betydelse?
/MagnusSv: Kineska tecken