vector push back with string.

hey guys in a program i am writing in one segement, i want to increase the size of vector that contains string. the process i normally use to push_back vector containing integer is not working.

1
2
3
4
5
6
7
8
  vector<string> string_vector(1);
  string_vector.push_back(1);///shows error.

while

  vector<int> int_vector(1);
  int_vector.push_back(1);///does work

any help would be appreciated!
1
2
3
  string_vector.push_back(1);///shows error.
                          ^
                    1 is not a string
doesn't push_back increase the number of vector 'containers'.eg:
1
2
vector<string> string_vector(1);///contains 1 'container'
 string_vector.push_back(1);///adds 1 more containers(total 2 containers) at 1st index 

doesn't it work that way?

so
1
2
vector<string> string_vector(1);
string_vector.push_back("5");///shows error 

1.is '5' added at 1stindex?


doesn't push_back increase the number of vector 'containers'

It always increases the size by 1. A copy of the value that you passed to push_back is added to the end of the vector.

http://www.cplusplus.com/reference/vector/vector/push_back/
Last edited on
got it. thanks.
@peter87 out of context and no offence but i can't seem to win even the very easy level of brum brum rally and it has begun to really annoy me now!.
Haha :D While making the game I become kind of good at it so it wasn't easy to know what is easy and what is hard. If you find it difficult to drive past the opponents you can try turning off the car collisions.
Last edited on
Topic archived. No new replies allowed.