I'm almost definitely being an idiot but can anyone please explain why adding another vector<int> to the following code would stop it from working.
Working code:
Code:
#include <iostream>
#include <vector>
using std::cin; using std::cout;
using std::endl; using std::vector;
int main ()
{
//generate list of cubes separated into collections by digit
vector<int> cubes5;
vector<int> cubes4;
vector<int> cubes3;
int cube;
int root = 1;
while (cube < 100000){
cube = root*root*root;
if (cube > 100 && cube < 1000)
cubes3.push_back(cube);
if (cube > 1000 && cube < 10000)
cubes4.push_back(cube);
if (cube > 10000 && cube < 100000)
cubes5.push_back(cube);
++root;
//output for debugging purposes
cout << root << " " << cube << endl;
}
return 0;
}
This works perfectly (please note this is the start of something longer chopped down to make a shorter, working example for this post)
However, if I declare another vector<int> at the beginning, the code compiles without any warnings but when run outputs nothing.
Problematic code:
Code:
#include <iostream>
#include <vector>
using std::cin; using std::cout;
using std::endl; using std::vector;
int main ()
{
//generate list of cubes separated into collections by digit
vector<int> cubes5;
vector<int> cubes4;
vector<int> cubes3;
vector<int> trouble;
int cube;
int root = 1;
while (cube < 100000){
cube = root*root*root;
if (cube > 100 && cube < 1000)
cubes3.push_back(cube);
if (cube > 1000 && cube < 10000)
cubes4.push_back(cube);
if (cube > 10000 && cube < 100000)
cubes5.push_back(cube);
++root;
//output for debugging purposes
cout << root << " " << cube << endl;
}
return 0;
}
I am sure there is a very simple explanation as to why declaring another vector<int> would have this effect but so far it escapes me.
Any advice or pointers would be most appreciated. Thank you.