Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between .dat and .txt in c++

Tags:

c++

file

record

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.

like image 593
Kumar Avatar asked Mar 06 '14 07:03

Kumar


2 Answers

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.

like image 195
Rahul Tripathi Avatar answered Oct 06 '22 16:10

Rahul Tripathi


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.

like image 23
AndersK Avatar answered Oct 06 '22 15:10

AndersK