Initialising unique variables in a while loop?

Hi,

I have an if statement nested in a while loop. Everytime the if statement is true I need to store a variable which can be used after the while loop is finished. The number of times the loop will run is variable. Is there an easy way of doing this? I could probably declare variables before the loop runs but how would I get program to change the variable name each time the if statement was met so that values were stored in different variables?

Thanks!
1
2
3
4
5
6
7
8
vector<int> variableStore;

while (somecondition)
{
  // generate someValue that you might want to store
  if (wantToStoreAValue)
  {  variableStore.push_back(someValue); }
}
Topic archived. No new replies allowed.