C ++如何在条件if语句中捕获int值,并在if语句改变之前显示它

时间:2017-03-24 18:21:36

标签: c++ if-statement get

    void Asteroids::OnScoreChanged(int score)
    {

       std::ostringstream msg_stream;
       std::ostringstream msg_stream2;
       std::ostringstream msg_stream3;


       msg_stream << "Score: " << score;
       msg_stream2 << "You scored: " << score;
       msg_stream3 << "diff score: " << score;

       // Get the score message as a string
       std::string score_msg1 = msg_stream.str();
       std::string score_msg2 = msg_stream2.str();
       std::string score_msg3 = msg_stream3.str();
       mScoreLabel->SetText(score_msg1);
       // need the value of score_msg2 below outside the if statement

       if (count == 1) {
          mTempLabel->SetText(score_msg2);
       }

      //and display it here when count = 2 but it changes when count increments

       if (count == 2) {
           //attempt to display score when count = 1
           mTempLabel2->SetText(score_msg2);
           mTempLabel2->SetText(score_msg3);
       }
   }

我想保存&#39;得分&#39;只有当count = 1时才显示整数,并且当count = 2时显示整数,问题是&#39;得分&#39;当count = 2时改变,所以当count = 1时得分的值是不同的,我如何保存或结合得分的值?当count = 1并将其显示在If语句之外(或其他任何地方)之前它会改变

0 个答案:

没有答案