I need to make a function that can choose a single vector element erase it and insert a new value in its place. The new value has to be a string. I have some code that I started on, but I think that I need to do some converting using sstream, I don't know. Here it is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void editFile (vector<string> &equation)
{
dispFile(equation);
int edit;
string data;
cout << "Choose the question to edit: ";
getline (cin, edit);
int element = equation.erase(edit-1);
cout << "Enter new data: ";
getline (cin, data);
equation.insert(element, data);
}
The display function looks like this:
1 2 3 4 5 6 7
void dispFile (vector<string> equation)
{
for (int i = 1; i < equation.size(); i++)
{
cout << i << ": " << equation[i-1] << endl;
}
}
My program is a teachers program for creating simple quadratic questions for students (eg. 3x^2 + 2x - 9). The teacher can write an entire list of questions with my program and save them to a file. The program can also display the current list again, but now I want to have another option in my menu that allows the teacher to look at the list and choose one of the questions and change it. Then after they could re-save the file or continue to edit more questions. The display would show a numbered list: