(void) and if (0) are standard idioms for intentional do-nothing code, so no warnings will be produced by using them.
This is wrong enough to misinform. (void) does not mean "do nothing code" in any technical sense. Casting like this is an explicit way to say that the return value of some statement will be ignored. The only reason here it doesn't run is because if (0) never executes code underneath it.
Code:
#include <cstdio>
int main() {
(void) std::printf("hello, world\n");
}
// my result: hello, world
if (0) was only common practice in C, as a specific use of goto to handle cleanup or other operations at the end of a function if an error occured. With RAII and exception handling, this practice is not needed in C++ at all.
If anything, this code sounds like it needs to be written in terms of iterators whose value type is `char`. That way, it's zounds more readable, probably more well-behaved and more natural to C++.
I consent with Mutant John too. I was trying to think of what code would really work like what OP wants. The first thing I thought of doing was getting iterators from the container passed in and then using the STL. So maybe just writing the code with iterators will be enough.