Hello everyone welcome back to my channel to day i am providing you What is binary file in C++. In this series i use Visual studio for coding.
Download first of left.
When you finished open it and setup. You can also read how to install Visual Studio. Choose Create a project.
- Choose Empty project.
Click Create to start.
double click on source files, add and add new item.
Click on C++ file, fill your solution name then click on add. Okay let start.
Okay let me show you some benefits of binary file in C++:
- Access faster.
- light.
- Security your data.
- Easier to access than text file.
- Read one for all, write one for all.
To start we have to include fstream to manipulation on file.
To manipulation with file we have two concept:
- ifstrem(use for read data from file to program).
- ofstream(write data from program into file).
So now we start with ifstream. back to desktop import a text file and than rename it's tail from .txt to .dat. After that right mouse, choose properties then copy it's location and past into your program.
All of the following is syntax so you can copy from mine. Remember to use binary mode and change forward slash to back slash because in C++ '' is special character and remember use this sentence readfromfile.close(); before return 0; if you don't have that your program will be scratch.
Let's let user input what they want
declare a struct Data in it we have an interger n use to save data when we read from file.
use syntax read to read all data from file to program. Finish.
if your program well the exited code will 0.
That all about read data from binary file. Thank for reading. Remember practice, challenge and not affraid of difficulties.