Page 2 of 2
Re: Looking for advice on programming
Posted: Mon Jul 06, 2009 1:07 am
by zodiac976
I might post it once I am done with it. I need to do some
more error checking and stuff
.
The ATM sim is basically just the menu but the login could
be somewhat like the card reader in a way.
You could also use it for like keeping up with your own budget
and stuff ;P because it constantly updates the balance of course
I am not sure how it would act if the power went out or the
program stopped all of a sudden.
Re: Looking for advice on programming
Posted: Mon Jul 06, 2009 10:51 am
by dandymcgee
programmerinprogress wrote:well you could just use an fstream to a file on the floppy disk right?
AFAIK streams are pretty indescrimiate of what you're reading from/writing too, just as long as you provide the correct information, but saying that, I've never tried it, so I am somewhat speculating
You know, I've never tried fstream anywhere but the project's folder but it should work.
EDIT: It works!
main.cpp
Code: Select all
#include <iostream>
#include <fstream>
using namespace std;
int main() {
string text = "I wonder if this is going to write itself to the floppy disk?!";
ofstream fileOut;
fileOut.open("A:\\account.txt");
while( !fileOut.is_open() ) {
cout << "Insert floppy disk in drive A: and press ENTER to continue...\n";
cin.get();
fileOut.open("A:\\account.txt");
}
fileOut << text;
fileOut.close();
cout << "Successful write!\n";
cin.get();
return 0;
}
Re: Looking for advice on programming
Posted: Mon Jul 06, 2009 12:56 pm
by zodiac976
dandymcgee wrote:programmerinprogress wrote:well you could just use an fstream to a file on the floppy disk right?
AFAIK streams are pretty indescrimiate of what you're reading from/writing too, just as long as you provide the correct information, but saying that, I've never tried it, so I am somewhat speculating
You know, I've never tried fstream anywhere but the project's folder but it should work.
EDIT: It works!
main.cpp
Code: Select all
#include <iostream>
#include <fstream>
using namespace std;
int main() {
string text = "I wonder if this is going to write itself to the floppy disk?!";
ofstream fileOut;
fileOut.open("A:\\account.txt");
while( !fileOut.is_open() ) {
cout << "Insert floppy disk in drive A: and press ENTER to continue...\n";
cin.get();
fileOut.open("A:\\account.txt");
}
fileOut << text;
fileOut.close();
cout << "Successful write!\n";
cin.get();
return 0;
}
I use file streaming a lot on all my projects for saving data.
By the way, using this:
ifstream file("test.txt");
has the same effect as:
ifstream file;
file.open("test.txt");
Just saves you an extra line if you didn't know that already.
EDIT: some people say this line is bad to use:
while(!file.eof());
{
}
I use it anyways and don't have problems with it and you can
stick an if statement in there like:
if("string variable".empty() == true)
{
break;
}
Will keep it from inserting an empty line at the end.
Re: Looking for advice on programming
Posted: Mon Jul 06, 2009 4:56 pm
by dandymcgee
zodiac976 wrote:I use file streaming a lot on all my projects for saving data.
Me too, but I've never tried writing to a floppy before. I wasn't 100% sure if FAT would make anything different, although I didn't think it would. Turns out it works just the same.
Re: Looking for advice on programming
Posted: Mon Jul 06, 2009 7:30 pm
by programmerinprogress
Yeah, I mean I was pretty sure it would work, but I never tried it, it's actually quite a cool representation of an ATM card
As for file streams, they know nothing about the application or purpose of the data, they just take it in or send it out to the specified file, very clever stuff indeed :D
Re: Looking for advice on programming
Posted: Tue Jul 07, 2009 8:17 am
by zodiac976
I got to looking at my ATM simulator(new version) again
and it is funny how you make something, look at it after
it is done then you realize why in the world did I do it this
way or why didn't I do this instead
.