Currently using Dev C++ and I was wondering how do I go about adding a data
file to my program. I created the data file and don't know how to link the two
together. I tried using a project folder and I put the .cpp and the .txt with
in the folder but it still doesn't notice it. I'm oviously missing a step or
two. Maybe even three! Please someone save me. My instructor wants me to use
this:
include<iostream>
include<fstream>
using namespace std;
.......
ifstream fin("employee.in");
......
while(fin>>employeeid>>hoursworked>>hourlyrate){..........}//end of loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Currently using Dev C++ and I was wondering how do I go about adding a data
file to my program. I created the data file and don't know how to link the two
together. I tried using a project folder and I put the .cpp and the .txt with
in the folder but it still doesn't notice it. I'm oviously missing a step or
two. Maybe even three! Please someone save me. My instructor wants me to use
this:
include<iostream>
include<fstream>
using namespace std;
.......
ifstream fin("employee.in");
......
while(fin>>employeeid>>hoursworked>>hourlyrate){..........}//end of loop
Simple, add it as resource.
ifstream fin("employee.in"); makes an ifstream object and a stream between
employee.in(the name of the file) and fin(the name of the object)
fin>>employeeid>>hoursworked>>hourlyrate; insert 3 first values in the file
to, employeeid hoursworked hourlyrate...
If off course employee.in is a text file. if it is a binary you must use read
and write functions.
the employee.in must be to the same folder with the .exe of your prgramm