I am trying to find code that will allow my data-entry program retain the data entered into it by a user once the program has been converted to an exe and put on the computer desktop.
The problem is that I've scoured the net but am generally unfamiliar with the relevant jargon.
Several tutorials regarding fstream and binary fstream which I only THINK are what I need, have proved to be so user unfriendly that I just cannot understand them, ie;
Input/Output with files
fstream - C++ Reference
and daniweb and Learncpp.com. None of these seem to address my problem, although I did learn to
write to a file out of these tutorials, which was relatively straightfoward.
I just want to know if there is a tutorial that will show me the code I need to write into my program so that when it is converted to a exe the user can enter information and then later add more data and so on, even after the program has been turned off, in the same way as any normal data base program operates. The information needs to be stored. I wrote a data base program and each time the computer is turned off or the program turned off, the information entered is lost.
Thanks for anyone directing me to a site covering this, or taking the time to show me the relevant code.
Making an .exe program store data as entered by the user
Started by squid attack, Oct 08 2010 01:52 AM
7 replies to this topic
#1
Posted 08 October 2010 - 01:52 AM
|
|
|
#2
Posted 08 October 2010 - 04:33 AM
It's pretty simple, as you've said already. Basicly you open file, write to it or read from it and that's what you need to do. You already wrote to it, just make your program like so that when it starts it loads (reads data from your file) data and then do whatever you want with it.
C programming - File I/O
C programming - File I/O
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#3
Posted 08 October 2010 - 01:47 PM
Thanks. In that link the code is;
My question is why does it only retrieve the word 'this' from the string.ie; //Reads one string from the file.
Even if I put char str[100] or change it to a string other errors occur?
Why is the full data not being printed.
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
char str[10];
ofstream a_file ( "example.txt" );
a_file<<"This text will now be inside of example.txt";
a_file.close();
ifstream b_file ( "example.txt" );
//Reads one string from the file
b_file>> str;
//Should output 'this'
cout<< str <<"\n";
cin.get();
}
My question is why does it only retrieve the word 'this' from the string.ie; //Reads one string from the file.
Even if I put char str[100] or change it to a string other errors occur?
Why is the full data not being printed.
#4
Posted 08 October 2010 - 02:20 PM
You have to read from file in a loop and check wheter you've reached EOF (End Of File). Also, I think that >> operator reads to the first occurance of space or new line so I suggest you use getline.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
ifstream file("file.txt");
if (!file) {
cout << "file not found\n";
return 1;
}
while (!file.eof()) { // read until eof is reached
getline(file, line);
cout << line;
}
return 0;
}
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#5
Posted 08 October 2010 - 02:53 PM
Right. Why didn't they put that in the tutorial??
Also, does that mean that the code you showed, need to be written each and every time various functions are required to retrieve data from the file within my program?
Also, does that mean that the code you showed, need to be written each and every time various functions are required to retrieve data from the file within my program?
#6
Posted 08 October 2010 - 04:01 PM
squid attack said:
Right. Why didn't they put that in the tutorial??
Also, does that mean that the code you showed, need to be written each and every time various functions are required to retrieve data from the file within my program?
Also, does that mean that the code you showed, need to be written each and every time various functions are required to retrieve data from the file within my program?
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#7
Posted 08 October 2010 - 04:24 PM
squid attack said:
Right. Why didn't they put that in the tutorial??
Quote
Also, does that mean that the code you showed, need to be written each and every time various functions are required to retrieve data from the file within my program?
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#8
Posted 08 October 2010 - 04:39 PM
No worries, thanks.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









