vector<string> with commands c++

I need help on the void insert function please. How do I get it to output the insert and the index function ?

Write a program that creates a vector of strings called V. Vector V grows and shrinks as the user processes the transactions from a data file called “data.txt”. The transaction file can only include three commands: Insert, Delete and Print. With Insert command, you get two more information, the information you need to insert and the position it should be inserted. With Delete, you get one more information that indicates which element (index) should be deleted. Print command means the content of the vector should be printed on the screen. For example, you may have the following information in your file:
Insert Hello 4
Delete 5
Print

Also the directions are saying to Test your program with the following transaction file. But what is a transaction file?
And if it is not to much to ask can I get some feed back from this code like wether or not to have the vector as a constant?
Thanks so much!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <fstream>
#include <vector>
#include <string>

using namespace std;

void insert(vector<string>v,  string, int);
void Delete(vector<string>v, int);
void Print(vector<string>v);

int main()
{

  vector <string>v;
  string operation, value;
  int index;

  ifstream inputFile;
  inputFile.open("data3.txt");

  if(!inputFile)
    {
      cout << "ERROR";
    }
  else
    {
      while (inputFile >> operation >> value>> index)
        {

      if (operation == "insert")
        {
          insert(v, value, index);
        }
      else if (operation == "Delete")
        {
          Delete(v, index);
        }
      else if (operation == "Print")
        {
          Print(v);
        }
        }

      inputFile.close();

    }
  return 0;
}

void insert( vector<string>v, string value, int index)
{
  for (int i=0; i< value.size(); i++)
    {
      cout<< value[i];
    }
  for(int i=0; i< v.size(); i++)
    {
      cout << v[i];
    }
}

void Delete(vector<string>v, int index)
{
}

void Print(vector<string> v)
{
}


Last edited on
what's inside your data3.txt?
it is this:
Insert Hello 4
Delete 5
Print
OP: don't start multiple threads on the same topic, how do you think it helps?
http://www.cplusplus.com/forum/beginner/207843/
Last edited on
Topic archived. No new replies allowed.