Thameera Senanayaka
Allion Technologies
#include <iostream>
int main() {
const char* str = "Hello";
std::cout << str << std::endl;
std::cout << strlen(str) << std::endl;
}
Hello
5
#include <iostream>
int main() {
const char* str = "こんにちは";
std::cout << str << std::endl;
std::cout << strlen(str) << std::endl;
}
こんにちは 10
#include <iostream>
int main() {
const wchar_t* str = L"こんにちは";
std::wcout << str << std::endl;
std::wcout << wcslen(str) << std::endl;
}
.
#include <iostream>
#include <fcntl.h>
#include <io.h>
int main() {
_setmode(_fileno(stdout), _O_WTEXT);
const wchar_t* str = L"こんにちは";
std::wcout << str << std::endl;
std::wcout << wcslen(str) << std::endl;
}
こんにちは
5
#include <iostream>
int main() {
std::cout << sizeof(wchar_t) << std::endl;
}
2
#include <iostream>
#include <fcntl.h>
#include <io.h>
int main() {
_setmode(_fileno(stdout), _O_WTEXT);
const wchar_t* str = L"こんにちは";
std::wcout << int(&str[0]) << std::endl;
std::wcout << int(&str[1]) << std::endl;
std::wcout << int(&str[2]) << std::endl;
}
10115120
10115122
10115124
#include <iostream>
#include <fcntl.h>
#include <io.h>
int main() {
_setmode(_fileno(stdout), _O_WTEXT);
const wchar_t* str = L"hello";
std::wcout << int(&str[0]) << std::endl;
std::wcout << int(&str[1]) << std::endl;
std::wcout << int(&str[2]) << std::endl;
}
17061936
17061938
17061940
#include <iostream>
#include <fcntl.h>
#include <io.h>
int main() {
_setmode(_fileno(stdout), _O_WTEXT);
const char* str = "hello";
const size_t size = strlen(str) + 1;
wchar_t* wstr = new wchar_t[size];
mbstowcs(wstr, str, size);
std::wcout << wstr << std::endl;
}
hello
#include <iostream>
#include <fcntl.h>
#include <io.h>
int main() {
_setmode(_fileno(stdout), _O_WTEXT);
const wchar_t* wstr = L"hello";
const size_t size = wcslen(wstr)+1;
char* str = new char[size];
wcstombs(str, wstr, size);
std::wcout << str << std::endl;
}
hello
#include <iostream>
#include <fcntl.h>
#include <io.h>
#include <string>
int main() {
_setmode(_fileno(stdout), _O_WTEXT);
std::wstring wstr = L"こんにちは";
std::wcout << wstr << std::endl;
}
こんにちは
LPCSTR str = "Hello";
typedef __nullterminated CONST CHAR *LPCSTR, *PCSTR;
LPCWSTR wstr = L"Hello";
typedef wchar_t WCHAR;
typedef __nullterminated CONST WCHAR *LPCWSTR, *PCWSTR;
MessageBoxW(NULL, L"Test", L"Title", MB_OK);
int
WINAPI
MessageBoxW(
__in_opt HWND hWnd,
__in_opt LPCWSTR lpText,
__in_opt LPCWSTR lpCaption,
__in UINT uType);
#ifdef UNICODE
#define MessageBox MessageBoxW
#else
#define MessageBox MessageBoxA
#endif // !UNICODE