just a data base question.

I just have a question, if you are writing a code to read from a data base, is it better that the data base is in .xlxs .csv or .txt.?
What file format is the best to pull data from that would work well with c++ code?
Thanks in advance.
I just have a question, if you are writing a code to read from a data base, is it better that the data base is in .xlxs .csv or .txt.?

That depends on what you call a "data base". Normally a "real" data base has it's own file format to hold the data and you must "export" the data to use the information in some other application.

What file format is the best to pull data from that would work well with c++ code?

Again this depends on the above. Since all three of the extensions you mentioned are "text" file formats you could possibly use any one of the three, however with .xlxs you may want to use a existing library to help read the information, .csv files are, IMO, probably the easiest to understand since each line should contain the same amount of elements.

When you say "data base", Oracle, MS SQL Server, MYSQL all come to mind.

.csv and .txt are simple text files. .txt being the easiest. You can define whatever rules you want for reading/writing data in a .txt file. I/O can be done simply through istream and ostream objects.

.csv files are also text files, but introduce some rules, such as commas (or other separator) between fields. Fields that include a comma need to be quoted. Embedded quotes need to be escaped. I find it easiest to have a class dedicated to reading/writing CSV files.

.xlsx files are also text files, but are in XML format. You can find information on the .xlsx format here:
https://en.wikipedia.org/wiki/Office_Open_XML
If you want to read or write .xlsx files, it is easiest to use one of the open source libraries to do so.



Keep in mind that modifying a txt (or csv, or xlsx) file almost certainly requires reading and rewriting the entire file. Depending on the size of your data and the frequency of updates, that might be intolerable.

If you use a database like Oracle, MySQL, etc, then you'll be using an API that the manufacturer publishes to access the data.
What I'm going to be doing is putting data on an excel or notepad form and I'm going to write a code so that I can only read from it (don't need to write). I was just wondering without spending money for any kind of software, which one would be the best and the easiest to use with c++.
I searched online and all I could find was that .xlsx was very difficult, but it could be done, .csv was kind of tough, and I could find anything on .txt.
Thanks for all the feedback.
What it really comes down to is, how complicated is your data? As already stated all three of the options you have listed are basically text files. If your data is very simple then a text file with all the "fields" on a line by their selves is probably the easiest solution, this would be one form of a .txt file.

The next option would be to have each record on it's own line with some kind of delimiter separating the fields. For simple information the separator can be any character that doesn't appear in the data. This is called a delimited file, normally the delimiter is a comma, which makes the file a Comma Separated File (.csv), although any separator can be used in a .csv file, including a space (but remember that your fields can't contain spaces something like "Tom Jones" would be two fields in a space separated file).

The last option would be to parse the .xlsx file it's self. This is a little more difficult than each of the preceding options, but it is possible. You will probably want to find and use an external library to aid in this endeavor. I do believe that there are a "few" open source (free) libraries available.

If you're going to be getting your data from Excel I would recommend you export the speadsheet as a simple Comma Delimited File and then use this file for your "data base". This way each record will have the same number of fields which each field separated by a comma, any "empty" fields are also delimited by a comma. So a record with three fields would look something like John,Paul,Jones or John,,Jones if there is no middle name. It's been a long time since I tried to export a file in Excel, but I think using quotes to surround strings is optional, unless your strings can include your delimiter, you can forgo this option.
Ok thanks, I think I understand.
I have lots of web searching to do
Topic archived. No new replies allowed.