Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ I cannot cout one string while i successfully cout an another string
    text
    copied!<p>i have a pretty weird problem. what im doing is im trying to convert a 8-digit binary number in a string to a decimal number (string also) at the end of the code i cout the binary string and the decimal string but when i ran, i only successfully see the binary string but not the decimal string...</p> <p>heres my code:</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;stdlib.h&gt; using namespace std; void bintodec(string bin); int main() { string bin=""; bintodec(bin); return 0; } void bintodec(string bin) { int temp; int temp_a; int temp_b; string dec; cout &lt;&lt; "Enter the binary number: "; cin &gt;&gt; bin; temp = 128*(bin[0]-48) + 64*(bin[1]-48) + 32*(bin[2]-48) + 16*(bin[3]-48) + 8*(bin[4]-48) + 4*(bin[5]-48) + 2*(bin[6]-48) + (bin[7]-48); temp_a = temp%10; temp = (temp - temp_a) / 10; temp_b = temp%10; temp = (temp - temp_b) / 10; dec[2]=temp_a+48; dec[1]=temp_b+48; dec[0]=temp+48; dec[3]='\0'; cout &lt;&lt; endl &lt;&lt; bin &lt;&lt; " in decimal is: " &lt;&lt; dec &lt;&lt; endl; } </code></pre> <p>and here is the running result:</p> <blockquote> <p>Enter the binary number: 10101010</p> <p>10101010 in decimal is:</p> </blockquote> <p>after "is" there should be my decimal number; however theres nothing. i tried to cout dec[0] dec[1] and dec[2] individually and it worked, but when i cout the whole dec, i failed every time...</p> <p>could anyone tell me where my problem is? i think i have something wrong with my code but i could figure it out...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload