Files C++

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();
}
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.
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
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.
Yeah That Is A Good Method. I'll Do That. Thank You
Don't capitalize every single word... it's irritating.
:)
Last edited on
Topic archived. No new replies allowed.