Chosing fstream file path

Currently this just dumps the user data into the main program file, is there anyway of me putting this user data into a file in the main program file called "players" ?
1
2
3
4
5
6
7
8
void UserCharacter::saveData()
{
	ofstream writer(username);
	writer << password << " " << baseDamage << " " << hp << " " << xp << " " << mapLevel << " "
		<< abilities[0] << " " << abilities[1] << " " << abilities[2] << " " << abilities[3] << " "
		<< backPack[0] << " " << backPack[1] << " " << backPack[2] << " " << backPack[3] << " " << backPack[4] << " " << backPack[5] << " "
		<< backPack[6] << " " << backPack[7] << " " << backPack[8] << " " << backPack[9];
}
hi,
write this instead:
1
2
3
4
5
6
7
8
void UserCharacter::saveData()
{
	ofstream writer("players");
	writer << password << " " << baseDamage << " " << hp << " " << xp << " " << mapLevel << " "
		<< abilities[0] << " " << abilities[1] << " " << abilities[2] << " " << abilities[3] << " "
		<< backPack[0] << " " << backPack[1] << " " << backPack[2] << " " << backPack[3] << " " << backPack[4] << " " << backPack[5] << " "
		<< backPack[6] << " " << backPack[7] << " " << backPack[8] << " " << backPack[9];
}

i don't know what username is, but if you want to save it into player file, this is the way
Solved

ifstream reader
reader.open("players/" + username + ".txt");
Topic archived. No new replies allowed.