Question: I'm having a minor problem when using putty c++ code, here are the instructions and my output yet Rich doesn't appear in my final output,

I'm having a minor problem when using putty c++ code, here are the instructions and my output yet "Rich" doesn't appear in my final output, and it should be included, so I need help fixing this problem, code and text file is below. Thanks in advance.

 I'm having a minor problem when using putty c++ code, hereare the instructions and my output yet "Rich" doesn't appear in my

// CODE

#include #include /* fstream header file for ifstream, ofstream, fstream classes */ #include #include

using namespace std;

int main() { string line; vector vec ; // Creation of ifstream class object to read the file ifstream fin; // by default open mode = ios::in mode fin.open("C:\\Users\\user\\Desktop\\Transaction.txt"); // Execute a loop until EOF (End of File) string cmd;//command string inf;//information(string) to be put into vector string ind;//index value read from input file int index;//index value read from input file converted to int type while (fin) { // Read a Line from File getline(fin, line); int i=0; cmd = ""; inf = ""; ind = ""; while(line[i]!='\0' && line[i]!=' ')//read command { cmd+=line[i]; i++; } if(cmd=="Add")//if command equals to Add then read the string to add and index { while(line[i]==' ') i++;

while(line[i]!=' ')//read string { inf+=line[i]; i++; } while(line[i]==' ') i++; while(line[i]!='\0' && line[i]!=' ')//read index { ind+=line[i]; i++; } index = atoi(ind.c_str());//convert index from string type to int type vec.insert(vec.begin()+index, inf);//add content at the index read } else if(cmd=="Remove")//if command equals to remove then read the index from which the string has to be removed { while(line[i]==' ') i++;

while(line[i]!='\0' && line[i]!=' ')//read index { ind+=line[i]; i++; } index = atoi(ind.c_str());//convert index from string type to int type vec.erase(vec.begin()+index);//remove content from the index read } else if(cmd=="Print")//if command equals to print then print all contents of vector { for (vector::const_iterator it = vec.begin(); it != vec.end(); ++it) cout

// Transaction.txt

Add Student 0 Add Kid 0 Add Final 1 Add Grow 1 Add Note 2 Print Add Rich 5 Remove 1 Remove 7 Add Mind 2 Remove 3 Print

Kid Grow Note Final Student Kid Note Mind Student

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!