Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cmath>
- using namespace std;
- void ignore_float(ifstream& ss);
- int main() {
- ifstream myfile("C:\\Users\\davyd\\Desktop\\2.txt", ios::in);
- ofstream o("C:\\Users\\davyd\\Desktop\\2.bin", ios::binary);
- int count = 0;
- float a;
- char buffer;
- float flag = NAN;
- while (myfile >> a)
- {
- count++;
- o.write((char*)&a, sizeof(a));
- myfile.get(buffer);
- //cout << a << " ";
- if (buffer == '\n') {
- //cout << endl;
- o.write((char*)&flag, sizeof(flag));
- }
- }
- myfile.close();
- o.close();
- ofstream txt("C:\\Users\\davyd\\Desktop\\2bin.txt");
- ifstream bin("C:\\Users\\davyd\\Desktop\\2.bin", ios::binary | ios::in);
- float b = 0;
- while (true) {
- if(bin.eof())
- break;
- if(isnan(b)){
- txt << endl;
- }
- bin.read((char*)&b, sizeof(b));
- txt << b << " ";
- }
- txt.close();
- bin.close();
- return 0;
- }
- void ignore_float(ifstream& ss) {
- float o;
- ss >> o;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement