Question

Lab 10 Write a program that reads the integer numbers in a text file (numbers.txt) and...

Lab 10

Write a program that reads the integer numbers in a text file (numbers.txt) and stores the numbers to a binary file (binaryNumber.dat). The number.txt file contains the following numbers:

1 2 3 4 5 6 7 8 9 0

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <fstream>
#include<iostream>
using namespace std;
int main() {
  
   ifstream is("numbers.txt");
   ofstream outFile;
    outFile.open("binaryNumber.dat", ios::binary );
   int x;
  
   while ( is >> x){  //Read data from numbers.txt file
   
      outFile<<x<<" ";  //Write data in binaryNumber.dat file
  }
        outFile.close();
   is.close();
}

INPUT:-

HA O O A dh TDM-GCC 4.9.2 64-bit Release C:\Users\Supriyo\Desktop\swap.cpp - Dev-C++ 5.11 File Edit Search View Project Execu

OUTPUT:-

C:\Users\Supriyo\Desktop\swap.cpp - Dev-C++ 5.11 File Edit Search View Project Execute Tools AStyle Window Help 口回归 BA HA O A

Add a comment
Know the answer?
Add Answer to:
Lab 10 Write a program that reads the integer numbers in a text file (numbers.txt) and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT