Well, you can silence the warning with a pragma:
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wunused-variable"
/code here/
#pragma GCC diagnostic pop
But I urge you not to do that. Given the tradeoffs, the "(void)dummy" option is better. I also urge you not to do a dummy inline function as advized by R Sahu, as this just obfuscates your code and unnecessary complexity.
I think in this case billz and moo-juice gave good advice. You are probably better off doing this with an old style for loop.
I can think of one situation where you might want to use the options discussed here. If the container "input" is of a type where getting the size requires traversing the range, and if the code in question is going to be in a performance critical area, you may find it worthwhile to optimize out iterating over the loop twice. In that case use:
(void) dummy; // silence uneccessary warning.
However this is almost certainly not the case in the example code you have posted, where io operations will dominate, making this a premature optmization.
Remember that you code will be read many more times than it will be written, so focus on what makes the code most readable. Using new C++ features is only a benefit if it bring an increase in the readability, maintainability, or flexibility of your code -- or if it brings a meaningful performance improvement.
In the case of the example you've posted, your guiding principle should be "what the easiest for a colleague to read?".