这两个函数对于读取文本文件非常有用。
<code class="lang-cpp">#include <windows.h> LPWSTR MakeTextW(LPVOID buf, INT_PTR cb, INT_PTR eatcch = 0, WCHAR replchr = L' ', BOOL reversed = FALSE) { LPWSTR str = (LPWSTR)buf; INT_PTR cch = cb / sizeof (WCHAR); for (int j = 0; j < cch - eatcch; j++) { WCHAR chr = str[j + eatcch]; if (reversed) chr = ((USHORT)chr >> 8) | ((USHORT)chr << 8); if (chr == 0) chr = replchr; str[j] = chr; } str[cch - eatcch] = 0; return str; } LPSTR MakeTextA(LPVOID buf, INT_PTR cb, INT_PTR eatcch = 0, CHAR replchr = ' ', BOOL reversed = FALSE) { LPSTR str = (LPSTR)buf; INT_PTR cch = cb / sizeof(CHAR); for (int j = 0; j < cch - eatcch; j++) { CHAR chr = str[j + eatcch]; if (chr == 0) chr = replchr; str[j] = chr; } str[cch - eatcch] = 0; return str; } int main() { HANDLE hin = GetStdHandle(STD_INPUT_HANDLE); HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE); DWORD count = 0; WCHAR buf[200] = L"3374\0" L"\u3500\u3700\u3500\u3800整周周\0" L"222"; CHAR bufa[200] = "3374\0" "5758整周周\0" "222"; // 31 字节 = 15 WCHARs + 1 奇数字节(忽略),开头吃一个字符,0替换为空格(默认),不转换字节序(默认) MakeTextW(buf, 31, 1); //MakeTextW(buf, 31, 1, 0x20, TRUE); WriteConsoleW(hout, buf, lstrlenW(buf), &count, NULL); WriteConsoleW(hout, L"\n", 1, &count, NULL); MakeTextA(bufa, 18, 1); WriteConsoleA(hout, bufa, lstrlenA(bufa), &count, NULL); WriteConsoleA(hout, "\n", 1, &count, NULL); return 0; }</windows.h></code>
[修改于 9年1个月前 - 2015/11/17 18:13:29]
时段 | 个数 |
---|---|
{{f.startingTime}}点 - {{f.endTime}}点 | {{f.fileCount}} |
200字以内,仅用于支线交流,主线讨论请采用回复功能。