if you want to do it yourself for study,
you can basically construct an integer by iterating the string.
string s = "1111"
int result = 0;
result << 1; //shift up. //first time zero has no effect.
result += (letter=='1'); //if the equality is true, add 1, else add zero
} //while have not done every letter
there are more efficient ways to do it if you were writing the c++ library you can do a lookup table for 8 bits worth and do it a byte at a time, for one.
Why do you still have lines 6 - 12? @nuderobmonkey's point was that inside the computer numbers are numbers are numbers. It's only the representation that changes. The conversion is done automagically, and you don't have to do anything.
By using a binary representation in line 4, the value 'num' is assigned, and can be printed out in decimal format in line 13. You don't have to do anything more. As a matter of fact, whatever you do in lines 6 - 12 is being ignored, so it's wasted code.