vector push back with string.

Apr 15, 2015 at 10:44am
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!
Apr 15, 2015 at 10:50am
1
2
3
  string_vector.push_back(1);///shows error.
                          ^
                    1 is not a string
Apr 15, 2015 at 11:00am
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?


Apr 15, 2015 at 11:15am
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 Apr 15, 2015 at 11:20am
Apr 15, 2015 at 11:19am
got it. thanks.
Apr 15, 2015 at 11:41am
@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!.
Apr 15, 2015 at 11:49am
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 Apr 15, 2015 at 11:51am
Topic archived. No new replies allowed.