user82069: For my understand, when building a new TX, need to produce a new scriptSig for the TX; and need add a sigHash code at the end of the TX. If the sighash type is SIGHASH_SINGLE, for a TX with multiple input and output, how to specify the right input and output to sign.  

user7272: A signature is applied to the input being signed by default, so you don't really pick the input.
You have two options:
SIGHASH_SINGLE - All inputs are signed, and a single output with the same vout index as your vin index is signed. That is to say, if you have a tx with 5 inputs, out of which your input is the second one, and 4 outputs, all five inputs and the second output will be signed.
SIGHASH_SINGLE | SIGHASH_ANYONECANPAY - This will only sign your input and the corresponding output, instead of signing all the inputs. Essentially, in the above example, input 2 and output 2 will be signed.

82069: <p>For my understand, when building a new TX, need to produce a new scriptSig for the TX; and need add a sigHash code at the end of the TX. If the sighash type is SIGHASH_SINGLE, for a TX with multiple input and output, how to specify the right input and output to sign.  </p>
 7272: <p>A signature is applied to the input being signed by default, so you don't really pick the input.</p>

<p>You have two options:</p>

<p><code>SIGHASH_SINGLE</code> - All inputs are signed, and a single output with the same vout index as your vin index is signed. That is to say, if you have a tx with 5 inputs, out of which your input is the second one, and 4 outputs, all five inputs and the second output will be signed.</p>

<p><code>SIGHASH_SINGLE | SIGHASH_ANYONECANPAY</code> - This will only sign your input and the corresponding output, instead of signing all the inputs. Essentially, in the above example, input 2 and output 2 will be signed.</p>
