std::ifstream* iStream = new std::ifstream(pszFilename, std::ios::in);
#define _UNICODE #define UNICODE
const wchar_t* FromTextFile = reinterpret_cast<const wchar_t*>(lpBuffer); MessageBox(nullptr, FromTextFile, FromTextFile, MB_ICONEXCLAMATION | MB_OK);
const wchar_t* FromTextFile = reinterpret_cast<const wchar_t*>(lpBuffer);MessageBox(nullptr, FromTextFile, FromTextFile, MB_ICONEXCLAMATION | MB_OK);
HANDLE hDFile = CreateFile(L"utf8_UsingByteOrderMark_C_天堂.txt", GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); DWORD NumberOfBytesWritten; BOOL bErr = 0; unsigned char BOM[3]{ 0xef, 0xbb, 0xbf }; // Write the BOM first. Do NOT write the BOM as part of the wstring or wchar_t which is item 2 of the WriteFile. bErr = WriteFile(hFile, (LPCVOID)BOM, (DWORD)sizeof(BOM), &dwBytesWritten, NULL); // Write the rest of the text; L"..." etc. AFTER writing the BOM. bErr = WriteFile(hDFile, L"hello - J - こんにちは - abcdefghijklmnopqrstuvwxyz", 90, &NumberOfBytesWritten, NULL); CloseHandle(hDFile);
bErrGHJ = WriteFile(hDFile, LpAll, Bytes_that_need_To_Write - bytes_which_have_written_already, &bytes_which_have_written_already, NULL);
//Create a file that has a BOM for utf-8 DWORD dwBytesWrittenXPP = 0; BOOL bErrGHJ = 0; TCHAR *flename = TEXT("utf8_ByteOrderMark.txt"); DWORD Bytes_that_need_To_Write; DWORD bytes_which_have_written_already = 0; int CountIt = 0; while (bytes_which_have_written_already< Bytes_that_need_To_Write ) { if (CountIt > 50) // To stop some loop until I can fix it. { break; } HANDLE hDFile = CreateFile(flename, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); unsigned char BOM48[3]{ 0xef, 0xbb, 0xbf }; wstring write_stuff77 = L"XYZ"; // Convert to two LPCVOID. LPCVOID Nf1 = (LPCVOID)BOM48; LPCVOID Nf2 = (LPCVOID)&write_stuff77[0]; // Convert to two wide strings. wstring wstrFirst(static_cast<const wchar_t*>(Nf1)); wstring wstrSecond(static_cast<const wchar_t*>(Nf2)); // Concatenate the two wide strings. wstring wstrAll = wstrFirst + wstrSecond; // Convert combined wstrings to LPCVOID. LPCVOID LpAll = (LPCVOID)&wstrAll[0]; wchar_t need_to_write_Bytes = wstrAll.size() ; Bytes_that_need_To_Write = sizeof (need_to_write_Bytes ) ; bErrGHJ = WriteFile(hDFile, LpAll, Bytes_that_need_To_Write - bytes_which_have_written_already, &bytes_which_have_written_already, NULL); bErrGHJ = CloseHandle(hDFile); CountIt = CountIt + 1; }
DWORD dwBytesWrittenXPP = 0; BOOL bErrGHJ = 0; TCHAR *flename = TEXT("utf8_ByteOrderMark.txt"); DWORD Bytes_that_need_To_Write; DWORD bytes_which_have_written_already; while (bytes_which_have_written_already< Bytes_that_need_To_Write ) { HANDLE hDFile = CreateFile(flename, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); unsigned char BOM48[3]{ 0xef, 0xbb, 0xbf }; wstring write_stuff77 = L"XYZ"; // Convert to two LPCVOID. LPCVOID Nf1 = (LPCVOID)BOM48; LPCVOID Nf2 = (LPCVOID)&write_stuff77[0]; // Convert to two wide strings. wstring wstrFirst(static_cast<const wchar_t*>(Nf1)); wstring wstrSecond(static_cast<const wchar_t*>(Nf2)); // Concatenate the two wide strings. wstring wstrAll = wstrFirst + wstrSecond; // Convert combined wstrings to LPCVOID. LPCVOID LpAll = (LPCVOID)&wstrAll[0]; wchar_t need_to_write_Bytes = wstrAll.size() ; Bytes_that_need_To_Write = sizeof (need_to_write_Bytes ) ; bErrGHJ = WriteFile(hDFile, LpAll, Bytes_that_need_To_Write - bytes_which_have_written_already, bytes_which_have_written_already, NULL); ) bErrGHJ = CloseHandle(hDFile);
wstring write_stuff = L"I am Happy"; DWORD dwBytesWritten = 0; TCHAR *fname=TEXT("A_Unicode_WriteSTuff_天_file.txt"); HANDLE hFile = CreateFile(fname, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); //BOOL bErr = WriteFile( hFile, DataBuffer, dwBytesToWrite, &dwBytesWritten, NULL); BOOL bErr = WriteFile( hFile, (LPCVOID)&write_stuff[0], sizeof(wchar_t)*write_stuff.size(), &dwBytesWritten, nullptr);
case WM_PAINT: { Processing_A_Buffer_Update = 1; PAINTSTRUCT ps; HDC_of_MainWindow = BeginPaint(hwnd, &ps); Draw_From_FRONT_BUFFER_001_To_MainWindow(); RECT rc; GetClientRect(hwnd, &rc); SetBkMode( ps.hdc, TRANSPARENT ); SetTextColor(ps.hdc, RGB(255, 0, 0)); DrawText(ps.hdc, L"Red Text on Transparent Background!", -1, &rc, DT_CENTER|DT_VCENTER|DT_WORDBREAK); SetBkMode( ps.hdc, OPAQUE ); SetTextColor(ps.hdc, RGB(255, 0, 0)); SetBkColor(ps.hdc, RGB(0, 255, 0)); DrawText(ps.hdc, L"\r\nRed Text on Green Background!", -1, &rc, DT_CENTER|DT_VCENTER|DT_WORDBREAK); SetBkMode( ps.hdc, TRANSPARENT ); SetTextColor(ps.hdc, RGB(0, 255, 0)); DrawText(ps.hdc, L"\r\n\r\nGreen Text on Transparent Background!", -1, &rc, DT_CENTER|DT_VCENTER|DT_WORDBREAK); SetBkMode( ps.hdc, OPAQUE ); SetTextColor(ps.hdc, RGB(0, 255, 0)); SetBkColor(ps.hdc, RGB(0, 0, 255)); DrawText(ps.hdc, L"\r\n\r\n\r\nGreen Text on Blue Background!", -1, &rc, DT_CENTER|DT_VCENTER|DT_WORDBREAK);
std::vector<std::string> v;
unsigned long StartTime_StringCreation = GetTickCount(); unsigned long StoppingTime_StringCreation; unsigned long MilliSeconds_StringCreation; double Seconds_StringCreation; std::string Time_StringCreation;
// For a string of length 1,000,000 to test how long it takes to create the string for (int s1 = 0; s1 <= 9; s1++) // String length = 1,000,000 { for (int kt = 0; kt <= 9; kt++) // String length = 100,000 { for (int w1 = 0; w1 <= 9; w1++) // String length = 10,000 { for (int np = 0; np <= 9; np++) // String length = 1,000 { StringBeingAdded = StringBeingAdded + "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; } } } }
StoppingTime_StringCreation = GetTickCount(); MilliSeconds_StringCreation = StoppingTime_StringCreation - StartTime_StringCreation; Seconds_StringCreation = (MilliSeconds_StringCreation) / 1000.0; Time_StringCreation = std::to_string(Seconds_StringCreation);
for ( unsigned long i = 0; i <= 100; i++ ) { v.emplace_back(StringBeingAdded); CountOfItems = CountOfItems +1; }
// With a string = "1" // 68,270,000 items in the array is about 3.671 seconds. // 68,280,000 is about [Microsoft Visual C++ Runtime Library Error] seconds.
// With a string of length 1,000,000 // 1,500 is about 4.703 seconds. // 2,000 is about [Microsoft Visual C++ Runtime Library Runtime Error] seconds.