I'm making a credit card applicatoin that models an ATM (its totally trivial). I had been getting just a little trouble saving my transactions towards the hard disk drive. The 2 primary questions are: A) Must I save it as being a DB or perhaps a text-file, B) Wouldso would I save to disk using either DB or txt format in STL C++ (I do not actually want to make use of a third-party library however i will if required).

Thanks ahead of time :-)

something similar to this:

#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}

However, you might want to try looking in to connecting SQLite for your application, as it is probably the most broadly distributed database on the planet: http://www.sqlite.org/capi3.html

It's solid, and it is used my many mobile products, and Thunderbird and Opera.

A database with this appears over kill just write one line towards the file per transaction. A helpful reference for that C++ streaming classes are available here http://www.cppreference.com/wiki/io/start - that also provides only a good general reference for C++

A) Must I save it as being a DB or perhaps a text-file,

Which will rely on the usage/application -- you're the best judge.

B) Wouldso would I save to disk using either DB or txt format in STL C++ (I do not actually want to make use of a third-party library however i will if required).

STL doesn't supply you with a a database driver. It will permit you to create output streams and save data as files-on-disk. If you are planning to create a DB-file, you should know concerning the internal format from the DB and write a binary file.

Text files are easy - <fstream> has got the class you will need - ofstream. Override operator << for the transaction class (you're utilizing a transaction class, right?), then just email the ofstream like you'd email cout.

If you're reasonably a new comer to C++, I'd suggest just logging transactions to a text file. The simplest method of doing this in C++ is by using an ofstream like so:

#include <fstream>

void write_transaction(ofstream& file, transaction t)
{
   file << t.somedata;
}

int main(int argc, char** argv)
{
   ofstream file;
   file.open("transactions.txt");
   transaction t;
   t.data = "Something";
   write_transaction(file, t);
   file.close();
   return 0;
}

Obviously, transaction is understood to be something which consists of all of your transaction data and would most likely take place in a wide array. write_transaction would then create all of the important data.

For C++ you might want to have a look at fstream.

If you're able to make use of an exterior (but very standard) library, boost's serialization might be a big help for you -- particularly if you are searching to dump the items in STL containers (not apparent if this sounds like what for you to do, out of your question).

Even when you cannot afford an exterior library, I'd recommend searching at just how serialization's api was created.

it mainly rely on the puropose of the project. if it's something serious, it is best to utilize a DB..other smart file is much better

really a while i simply make use of a file based db...