Advertisement
Fruch

Untitled

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