Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <iostream>
- #include <string>
- using namespace std;
- bool done;
- string Readpart(HANDLE h)
- {
- char szSymbol;
- char szBuffer[128];
- int i = 0;
- DWORD dwCount;
- do
- {
- ReadFile(h, &szSymbol, 1, &dwCount, 0);
- if (dwCount == 0) //проверка на конец файла
- {
- done = true;
- break;
- }
- szBuffer[i] = szSymbol;
- i++;
- } while (szSymbol != ' ');
- szBuffer[i] = '\0';
- return string(szBuffer);
- }
- void main()
- {
- setlocale(LC_ALL, "rus");
- string buff_1, buff_2;
- LPCTSTR filename = TEXT("test_1.txt");
- HANDLE h = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
- if (h != INVALID_HANDLE_VALUE)
- {
- while (true)
- {
- buff_1 = Readpart(h);
- if (done)
- break;
- buff_2 = Readpart(h);
- if (done)
- {
- cout << buff_1;
- break;
- }
- cout << buff_2 << " " << buff_1;
- }
- }
- CloseHandle(h);
- cout << endl;
- std::system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement