string half_password = password.str();
if(shift < 0) //left shift
rotate(half_password.begin(), half_password.begin() + (-1*shift), half_password.end());
if(shift > 0) //right shift
rotate(half_password.rbegin(), half_password.rbegin() + shift, half_password.rend());
|shift| の場合 > 7 で長さhalf_password
が 8 の場合、プログラムがセグメンテーション違反でクラッシュします。私の質問は、rotate
関数が文字列の最高インデックスを超える回転を許可しないということですか?
私はこれに問題はありません。ロジックは正常に機能します。これが機能の仕組みであるかどうかを知りたいのですrotate
が。