I am creating a employee information application were the user has the ability to create and update information. The user enters in the name of the person they want to update which is working correctly.
However when they want to update that person name I run into a issue. So far the best way I have though to update the users name would be to uses tellp once I found the data and subtracting that by the string length to determine the starting position. In theory I assumed that would over right the data when I uses seekp to set the position the data should start to be written to. But when ever I set seekp to the position I want it to write to it jumps back to the end of the file. Am I missing something with seekp that would cause this?
It might sound a little confusing but here is my code if it helps:
CODE
cout << "Update Records" <<endl;
cout << "Please enter in the name of the employee you would like to update" <<endl;
cout << "Employee: ";
getline(cin,empNameSearch); // Ask user to enter in the name of the employee they want to find the recrd of
// empNameSearch and empName are declared as strings
while(empNameSearch != empName) //Finds employees name (work in progress but dose not effect the issue I am having)
{
getline(dataFile,empName);
if(dataFile.eof())
{
cout << "A record for " << empName << " could not be found" <<endl;
cout << "Please check your data and try again" <<endl;
main();
}
}
position = dataFile.tellp(); //position declared as int
stringSize = empName.size(); //string size declared as int
position = (position - stringSize); //Determine the start point of the orginal name
dataFile.seekp(position); //Sets the position to write data to
cout << "Please enter in the employees new name" <<endl;
cout << "Employee: ";
getline(cin,empName); //Gets updated name from user to write to file
dataFile << empName; //Writes empName string back to file (Here is the issue cause it wont write it to the point I set seekp to
Also I am open to suggestion of other methods about updating the users name with the new one. So if tellp and seekp are not the best please feel free to mention it.