Advertisement
Fruch

Untitled

May 10th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. bool done;
  7.  
  8. string Readpart(HANDLE h)
  9. {
  10. char szSymbol;
  11. char szBuffer[128];
  12. int i = 0;
  13. DWORD dwCount;
  14. do
  15. {
  16. ReadFile(h, &szSymbol, 1, &dwCount, 0);
  17. if (dwCount == 0) //проверка на конец файла
  18. {
  19. done = true;
  20. break;
  21. }
  22. szBuffer[i] = szSymbol;
  23. i++;
  24. } while (szSymbol != ' ');
  25. szBuffer[i] = '\0';
  26.  
  27. return string(szBuffer);
  28. }
  29.  
  30. void main()
  31. {
  32. setlocale(LC_ALL, "rus");
  33. string buff_1, buff_2;
  34. LPCTSTR filename = TEXT("test_1.txt");
  35. HANDLE h = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  36. if (h != INVALID_HANDLE_VALUE)
  37. {
  38. while (true)
  39. {
  40. buff_1 = Readpart(h);
  41. if (done)
  42. break;
  43. buff_2 = Readpart(h);
  44. if (done)
  45. {
  46. cout << buff_1;
  47. break;
  48. }
  49. cout << buff_2 << " " << buff_1;
  50. }
  51. }
  52. CloseHandle(h);
  53. cout << endl;
  54. std::system("pause");
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement