How to specify the right input and output to be signed for SIGHASH_SINGLE 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.
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.