Files C++

Sep 23, 2011 at 7:12am
I Want To Keep A Separate File For Each And Every Employee In My Program. In My Program I Will Store Details About Employees. I'm Creating A Random Number As Employee-Number. And I Want To Set The File Name To That Employees Employee-Number.I Know How To Create A Text File And Stuff. This I What I Have In My Mind.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
void AddEmp::WritingToFile(int TEMP_STAFFNUM)
{

	ofstream myfile;
	myfile.open("TEMP_STAFFNUM.txt");//I Want To Set The File Name To Be Numeric Staff /number
	myfile<<"/";
	myfile<<department;
	myfile<<"/";
	myfile<<"#"<<TEMP_STAFFNUM;
	myfile<<"/";
	myfile<<name;
	myfile<<"/";
	myfile<<nic;
	myfile<<"/";
	myfile<<gender;
	myfile<<"/";
	myfile<<designation;
	myfile<<"/";
	myfile<<dateJoined;
	myfile<<"/";
	myfile<<nationality;
	myfile<<"/";
	myfile<<religion;
	myfile<<"/";
	myfile<<dob;
	myfile<<"/";
	myfile<<status;
	myfile<<"/";
	myfile.close();
}
Sep 23, 2011 at 8:49am
You should look up converting an int into a string.
Also getting a random number is a bad idea as it leaves the possibility of multiple employees having the same ID.
Sep 23, 2011 at 9:03am
But What If I check The Random Number Before I Add A New Employee. It Mean Everytime I Add A New Employee I Check The Availability Of The Number.

Thank You For Your Help
Sep 23, 2011 at 10:24am
You could do this, but it would require checking all employees each time you add one. I'd just start at 1 and just add 1 every time you add a new employee.
Sep 23, 2011 at 12:02pm
Yeah That Is A Good Method. I'll Do That. Thank You
Sep 23, 2011 at 12:22pm
Don't capitalize every single word... it's irritating.
Sep 23, 2011 at 3:54pm
:)
Last edited on Sep 25, 2011 at 3:51am
Topic archived. No new replies allowed.