Apr 14, 2013 at 8:23pm Apr 14, 2013 at 8:23pm UTC
Why are you passing the size for a vector?
An
std::vector knows its own size, just like all other STL containers I can think of.
So your
for() loop should rather look like:
1 2
for (vector<bool >::size_type count = 1; count <= binary.size(); ++count)
decValue += res*((binary[count-1]*2)^count);
Even this looks a bit awkward, in my opinion. Personally I would use a C++11 range-based
for() loop, a bit like this:
1 2 3 4 5
size_t count=1; // std::size_t can be found in cstddef header
float decValue = 0;
for (bool b: binary)
decValue += res * ((b*2) ^ count++);
Edit: formatting.
Last edited on Apr 14, 2013 at 8:31pm Apr 14, 2013 at 8:31pm UTC
Apr 14, 2013 at 11:44pm Apr 14, 2013 at 11:44pm UTC
Yeah but im still getting the error that says:
Expression: vector<bool> iterator not dereferencable
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.