I am trying to get output from a range based loop. If I use a 'standard' approach - iterating with a standard for loop it works as expected. I can see that. However I just wanted to try with a range based loop, but the output is not as expected. I understand the output, but I would like the value of the auto iterator. If you look at my code sample it should be clear...
The purpose of the range based for is to easily have access to de-referenced elements in a container. So your goal of trying to have access to a containers subscript isn't a suitable use for ranged based for.
Why are you storing these numbers as bool? Why not a vector of the number themselves? Maybe you want a std::bitset instead - if your goal is to save space?
Thanks for the reply. I maybe wrong, but the reason for the bool is in case the number has been randomly generated before, it will generate another random number and check for true again. If false it changes that bool at that index to true.
Basically trying to do it with a range based loop doesnt make sense. It does work if I create a variable int value = 0;
Then increment this with the loop, then when the iterator is true(1) print this variable.
Bit rubbish really.
You could try changing line 33 to std::cout << &it - &LotteryNumbers[0] << " ";
and relying on the elements of LotteryNumbers being in successive positions in memory.
I don't think it's what range-based for loops were designed for, though.