I am using .txt
files in my program for reading and writing records (records contains both text and numerals). Recently i came to know that .dat
file also can be used like .txt
for file operations. I would like to know the difference between the two and the advantages and disadvantages of one over another.
Text files or .txt
files are a bit hard to parse in programs and easy to read. whereas .dat
is usually used to store data that is not just plain text.
Generally .txt files contains letters, characters and symbols which is readable.
.dat
is binary text file in which data is not always printable on screen.
The extension of a file is a helper so that the operating system (or user) can choose the appropriate program to open it. The actual file contents do not matter. There are some conventions what extensions to use but there is nothing from keeping you to use any arbitrary extension for your files. For instance you can rename a .jar file to .zip-file and be able to open the file with pkunzip.
So for C++ the extension does not matter, but for you as a programmer it may give a hint of the file contents i.e. open it in text or binary mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With