Best way to store data in C ++
I'm just learning C ++, just started messing around with QT and I'm sitting here wondering how do most applications save data? Is there an industry standard? Do they save it in XML file, text file, SQLite? What about sensitive data that says accounting software will need to be stored? I'm just curious to know what are the best practices for this.
thanks
a source to share
This question is too broad. The only answer is that it depends on the nature of the particular application and data, and very little on whether it is written in C ++.
For example, user-configurable application settings are often stored in text files, but on Windows they are usually stored in the registry. Accounting applications usually store their data in some kind of database.
a source to share
There are many good ways to store application data (let's call it serialization).
Personally, I find that for larger datasets, using the open format is much easier to debug. For example, if you go with XML, you can keep your data in an open form so that if you have file corruption issues (i.e. the client cannot open the file for whatever reason) it is easier to find. If you have sensitive data, you can always encrypt it before writing it to a file using key encryption. Microsoft, for example, has moved away from using a proprietary format to open xml in its office documents. They use. * X extension (.docx, .xlsx, etc.). It's really just a compressed folder of xml files.
Using binary serialization is, of course, the industry standard for most standalone applications at the moment. This is most likely due to the application framework they are using (like MFC, which is old). If you take a look at most of the serialization techniques in modern application environments, XML serialization is very well supported.
a source to share
There is no standard practice, however, if you want to use complex structured data, consider using an embedded database engine such as SQLite or Metakit, or Berkeley DB files. XML files will also do the job and be read / write. Preferences can use INI files or Windows Registry etc. In short, it really depends on your usage pattern.
a source to share
This is a common question. As with many things, the correct answer depends on your application and its needs.
- Most desktop applications save the final data to a file (I think Word and Excel). The format is up to you, XML, binary, etc. And if you can serialize / deserialize objects to a file, that might make your life easier.
- Internal application data such as configuration files or temporary data can be saved in an XML file or in a light local database such as SQLite
- Often, "enterprise" applications used internally for business will store their data in an internal database such as SQL Server or Oracle. Thus, all plant data is stored in one central location. And then it is available for reports, etc.
For accounting software, you will need to consider the business domain and end users. For example, if the software is going to be sold to large businesses, you will likely use some form of database to store the data. If not, the binary would be right, perhaps with some form of encryption if you're really paranoid.
a source to share
When you say "the best way" then you have to define what you mean by "good".
The problem is that different requirements conflict with each other, so you cannot satisfy all of them at the same time.
For example, if one of the requirements is "concurrent multi-user access to data," then that would imply the use of a database engine, but this conflicts with "as little as possible" and "minimizes dependencies on third-party software."
If the requirement is a "portable data format" then it assumes XML, but this conflicts with "compact" and "indexed".
a source to share