push_back and pop_back not working

Feb 16, 2016 at 1:27am
here is a little test i wrote to demonstrate my problem

1
2
3
4
5
6
7
8
9
10
11
12
13
  std::vector<int> test(10);
  int num;
  for(int counter = 0; counter < 10; counter++)
  {
    std::cin>>num;
    test.push_back(num);
  }

//print it here
  for (int counter = 0; counter < 10; counter++)
  {
    std::cout << test[counter];
  }


whenever I try and print the array, it just prints 0's. Also, whenever i try to use pop_back, it never removes anything
Last edited on Feb 16, 2016 at 1:28am
Feb 16, 2016 at 1:33am
std::vector<int> test(10); // initializes them to 0

simply change it to std::vector<int> test;
Feb 16, 2016 at 1:35am
Thanks, oh god how did i not see that
Topic archived. No new replies allowed.