Convert characters to octal, binary, and integer
Unnecessary Headers
The #includes for iterator and bitset are not needed, the code compiles fine without them, iterator may be included indirectly through vector.

Adding unnecessary headers can increase compile/build times and may cause other problems in larger more complex programs.

Portability
This program is currently not portable for 2 reasons, the use of the Visual Studio generated #include "stdafx.h" and the use of the non-standard for each loop. It might be better to embed #include "stdafx.h" within ifdef/endif.

#ifdef windows
#include "stdafx.h"
#endif


I compiled this in Visual Studio 2017 on Windows 10 and it actually reported a compile error on the for each loop. The suggested fix was to use a range based for loop.

1&gt;------ Build started: Project: octbinintconv0, Configuration: Debug Win32 ------
1&gt;octbinintconv0.cpp
1&gt;d:\projectsnfwsi\codereview\octbinintconv0\octbinintconv0\octbinintconv0.cpp(18): warning C4244: '+=': conversion from 'double' to 'int', possible loss of data
1&gt;d:\projectsnfwsi\codereview\octbinintconv0\octbinintconv0\octbinintconv0.cpp(40): error C4496: nonstandard extension 'for each' used: replace with ranged-for statement
1&gt;d:\projectsnfwsi\codereview\octbinintconv0\octbinintconv0\octbinintconv0.cpp(55): warning C4018: '&lt;': signed/unsigned mismatch
1&gt;Done building project "octbinintconv0.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


You might want to replace the for each loop with the following code, which uses an iterator and is part of standard C++.

    for (auto c : buffer)
    {
        int x = c - '0';
        std::stringstream opt;
        opt &lt;&lt; std::setw(3) &lt;&lt; std::setfill('0') &lt;&lt; OctalToBinary(x) &lt;&lt; "\n";

        std::string val = opt.str();

        std::copy(val.begin(), val.end() - 1, std::back_inserter(collection));
    }


Type Mismatches
A good practice is treating warning messages as errors, since they point to potential logic errors. The pow() function returns double and the result is being truncated, it might be better to use a static cast in the code to show that this is intentional.

    decimalNum += (octalNum % 10) * static_cast&lt;int&gt;(pow(8, count));


In this for loop it would be better to define the local variable i as size_t rather than int, in any of the STL container classes the function size() returns size_t.

    for (size_t i = 0; i &lt; bitsize.size(); i++)


Complexity
Creating the function OctalToBinary(int octalNum) was good but there are two more functions that main() can be broken up into, they have even been identified by comments, both of the for loop are good candidates for functions.