std::bitset<9> a;
for(size_t i = 1;i <= 256;i++)
{
a = i;
std::cout<<a<<"\n";
}
which one is better?
I think that bitset would be slower than itoa but the space
would be smaller than the first solution
itoa is faster, but need more space and it is non-standard(I can write one for myself)
Is there any "absolute reoson" I should dump one of them?
Or could I just use bitset to finish the task if it wouldn't
become the bottle neck of my programs?
ps : My classmates told me I should use itoa, because itoa is far more better than bitset
I think the instantiation of a bitset might be a bottleneck. Try writing a special function specifically for binary (a generalized algorithm would be slower).
I don't think a generalized function has to be slower but I am pretty sure a bitset that small does have a little memory overhead. I would prefer the bitset approach--it's a very elegant solution that is both standard and very reliable.