I have read in the data from a file and have given the user multiple options on what they are allowed to do one of which is to edit lines of data. i created an infinite for loop that ends only when the user uses x or X when the edit option is chosen i have altered the vector but later on if i have user use the view option the vector seems unchanged
Why is it that although the vector is altered then asked to print out its info again alter on that it prints the older version of the vector but if you print the vector it shows its been altered
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <iomanip>
#include<fstream>
using namespace std;
const int NCOLS = 4;
const int NROWS = 10;
void description_and_options(vector<vector<string>> data, int count[NCOLS]);
void view_line_data(int choice, vector<vector<string>>data);
void available_options();
int main()
{
fstream file_name;//create the new file
string user_input_file;
vector<vector<string>>read_in_vector;
string user_option_choice;
string small_exit = "x";
string large_exit = "X";
int view_choice;
int edit_choice;
int counter[10] = { 1,2,3,4,5,6,7,8,9,10 };
string edit_row;
string edit_username, edit_password, edit_notes, edit_decision;
cout << "Enter the name of the input file: ";
cin >> user_input_file;
file_name.open(user_input_file.c_str());
if (file_name.fail())
{
cout << "File failed to open" << endl;
system("PAUSE");
exit(1);
}
**for (string line{}; getline(file_name, line);)
{
istringstream line_is{ line };
vector<string> row{};
for (string value{}; getline(line_is, value, ';');)
{
row.push_back(value);
}
read_in_vector.push_back(row);
}
file_name.close();
cin >> user_option_choice;**
for (int lcv = 0; lcv < 2;)
{
**if (user_option_choice == small_exit || user_option_choice == large_exit)
{
break;
}**
if (user_option_choice == "D" || user_option_choice == "d")
{
description_and_options(read_in_vector, counter);
available_options();
}/////////////////////////////////////////////////////////////D
**if (user_option_choice == "v" || user_option_choice == "V")
{
cout << "Enter line number you wish to view:" << endl;
cin >> view_choice;
view_line_data(view_choice, read_in_vector);
available_options();
}**
if (user_option_choice == "e" || user_option_choice == "E")
{
cout << "Enter line number you wish to edit:" << endl;
cin >> edit_choice;
view_line_data(edit_choice, read_in_vector);
cout << "WARNING: You cannot use semi-colons in these fields. Any semi-colons entered will be removed." << endl << endl;
//cout << "Enter a line description: " << endl;
**getline(cin, edit_row);**
cout << endl;
cout << "Enter a line description: " << endl;
**getline(cin, edit_row);**
cout << endl;
cout << "Enter a username: " << endl;
**getline(cin, edit_username);**
cout << endl;
cout << "Enter a password: " << endl;
**getline(cin, edit_password);**
cout << endl;
cout << "Enter notes: " << endl;
**getline(cin, edit_notes);**
cout << endl;
cout << "You have entered:" << endl;
cout << "Row Desc: " << edit_row << endl;
cout << "Username: " << edit_username << endl;
cout << "Password: " << edit_password << endl;
cout << "Notes: " << edit_notes << endl << endl;
cout << "Is this the data you wish to add (Y/N)? ";
cin >> edit_decision;
if (edit_decision == "N" || edit_decision == "n")
{
cout << "Line was not changed." << endl;
description_and_options(read_in_vector, counter);
}
if (edit_decision == "Y" || edit_decision == "y")
{
file_name.open(user_input_file.c_str());
//edit_line(read_in_vector , edit_choice, edit_row, edit_username, edit_password, edit_notes);
**read_in_vector[edit_choice][0] = edit_row;
read_in_vector[edit_choice][1] = edit_username;
read_in_vector[edit_choice][2] = edit_password;
read_in_vector[edit_choice][3] = edit_notes;
cout << read_in_vector[edit_choice][0];**
file_name << read_in_vector[edit_choice][0];
}
}
cin.clear();
cin.ignore(100, '\n');
cin >> user_option_choice;
}
system("PAUSE");
}
void description_and_options(vector<vector<string>>data, int count[NCOLS])
{
for (int lcv = 0; lcv < 9; lcv++)
{
cout << count[lcv] << " ";
cout << data[lcv][0] << endl;
}
cout << endl;
}
void view_line_data(int choice, vector<vector<string>>data)
{
choice = choice - 1;
cout << endl;
cout << "Row Desc: " << data[choice][0] << endl;
cout << "Username: " << data[choice][1] << endl;
cout << "Password: " << data[choice][2] << endl;
cout << "Notes: " << data[choice][3] << endl << endl;
}
void available_options()
{
cout << endl << " AVAILABLE OPTIONS" << endl << endl;
cout << "D - DISPLAY LINE DESCRIPTIONS" << endl;
cout << "V - VIEW LINE DATA" << endl;
cout << "E - EDIT LINE DATA" << endl;
cout << "A - ADD LINE DATA" << endl;
cout << "S - SAVE AND ENCODE FILE" << endl;
cout << "X - EXIT PROGRAM" << endl;
}
output Row Desc: Dragcave.net
Username: Dragonmaster27
Password: DragonM27
Notes: Notes: username shortend
WARNING: You cannot use semi-colons in these fields. Any semi-colons entered will be removed.
Enter a line description: Dragcave.com
Enter a username: Dragonmaster27
Enter a password: DragonM27
Enter notes: Notes: username shortend
You have entered: Row Desc: Dragcave.com Username: Dragonmaster27 Password: DragonM27 Notes: Notes: username shortend
Is this the data you wish to add (Y/N)? y
Dragcave.com
as you can see dragcave.net became .com but if you run through and print out using the V code it shows .net still