Reputation: 127
I am working on creating a bank system with C++(see: Can anyone give me advice on this bank system project? for more details).
What I would like to know is what I need to implement in my C++ code in order for it to be able to remember past inputs.
In my project, this would mean that after executing the code for the first time, and inputting my name or any other data (integer, float numbers), later on, if I execute the code again in the future (after closing the C++ execution window), I can go to the option “I already have an account” and use any inputs I had given the system before (deposits, birthplace...).
Can C++ do that or I need to use something like Visual Studio or Qt?
Thanks a lot in advance.
Upvotes: 0
Views: 802
Reputation: 19
try saving them in a file, and then read the input using ifstream. then you can take every line of the text (for example) and execute it using input redirection http://www.cplusplus.com/reference/fstream/ifstream/ here's the doc you'll need
Upvotes: 0
Reputation: 5660
To be able to recall past inputs, independent of program execution you will have to store that information.
The most simple approach would be to store the necessary information in a text file. More complex approaches involve databases.
View std::fstream for an example on how to use streams.
If you want some more convenience, you can of course also use Qt. QFile would be the way to go there.
A very simple database would be a file based one, e.g. SQLite. Qt also offers convenience in that regard, namely QSqlDatabase
For more control of the file based approach, you can choose a specific format, e.g. JSON, XML. Qt JSON Support, Qt XML Support
Upvotes: 4