vector insert function

i have a question regarding vector about having multiple info.
for example if i have a file that contained firstName lastName and numbers

if i do i: V.insert(V.begin() + first, last, numbers) is that correct way ?



can you even allow to do it like that?
Last edited on
can you even allow to do it like that?

No. You're misusing the comma operator.
Use a struct and push_back() the struct onto the vector.

1
2
3
4
5
6
7
8
9
10
11
  struct person
  {  string firstname;
      string lastname;
      int numbers;  // Or whatever type this is
  };

  person p;
  p.firstname = "Fred";
  p.lastname = "Flintstone";
  p.numbers = 1234;
  V.push_back (p);

Last edited on
@abstractionAnon

i havent learn struct yet and we are only allow to use vector.
Then use 3 vectors.
1
2
3
4
5
6
7
  vector<string> firstname;
  vector<string> lastname;
  vector<string> numbers;

  firstname.push_back ("Fred");
  lastname.push_back ("Flintstone");
  numbers.push_back ("123-45-6789");

Last edited on
Topic archived. No new replies allowed.