Advertisement
vlad_davydov

mv

Jul 13th, 2021
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4.  
  5.  
  6. using namespace std;
  7. void ignore_float(ifstream& ss);
  8.  
  9. int main() {
  10.  
  11. ifstream myfile("C:\\Users\\davyd\\Desktop\\2.txt", ios::in);
  12. ofstream o("C:\\Users\\davyd\\Desktop\\2.bin", ios::binary);
  13. int count = 0;
  14. float a;
  15. char buffer;
  16. float flag = NAN;
  17. while (myfile >> a)
  18. {
  19. count++;
  20. o.write((char*)&a, sizeof(a));
  21. myfile.get(buffer);
  22. //cout << a << " ";
  23. if (buffer == '\n') {
  24. //cout << endl;
  25. o.write((char*)&flag, sizeof(flag));
  26. }
  27.  
  28. }
  29. myfile.close();
  30. o.close();
  31.  
  32.  
  33.  
  34. ofstream txt("C:\\Users\\davyd\\Desktop\\2bin.txt");
  35. ifstream bin("C:\\Users\\davyd\\Desktop\\2.bin", ios::binary | ios::in);
  36. float b = 0;
  37. while (true) {
  38. if(bin.eof())
  39. break;
  40. if(isnan(b)){
  41.  
  42. txt << endl;
  43. }
  44.  
  45. bin.read((char*)&b, sizeof(b));
  46.  
  47. txt << b << " ";
  48.  
  49.  
  50.  
  51.  
  52. }
  53.  
  54.  
  55.  
  56. txt.close();
  57. bin.close();
  58.  
  59.  
  60.  
  61.  
  62. return 0;
  63. }
  64.  
  65.  
  66. void ignore_float(ifstream& ss) {
  67. float o;
  68. ss >> o;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement