【问题标题】:run time check failure #3 - t within the while loop运行时检查失败 #3 - while 循环内的 t
【发布时间】:2016-10-07 10:48:23
【问题描述】:

您好,我有一个关于运行时检查失败 #3 的问题。 我在 while 循环中使用了两个 if 语句。 我通过不初始化变量了解到失败#3 的原因。但是我在while循环之前做了。第一个 if 语句有效,但是当它到达第二个 if 语句时它会停止。在这种情况下请告诉我。

提前致谢。

贾斯汀

    int count = 0;

    while (1)
    { 
        cap >> src;

        if (count < 5)
        {
            cout << count << endl;
        }

        // error at the second if statement. 
        if (count == 4) 
        {
            cout << "here" << end;
            count = 0;
        }

        count += 1;

    }

【问题讨论】:

  • 这是一个无限循环。
  • 是的.. 还有更多功能,但为了简单起见,我将它们从我的问题中删除了.. 无限循环也不会导致“运行时检查失败 #3”..
  • 我认为你错过了从 endl 到 end 的拼写;有问题吗?

标签: c++ if-statement while-loop


【解决方案1】:

正如@pirate 所建议的,在您的第二个 if 条件下,您有拼写错误。

    if (count == 4) 
    {
        cout << "here" << end; // instead of end use endl here
        count = 0;
    }

测试了你的程序,它运行良好,没有任何错误。

【讨论】:

  • 我不敢相信这就是问题所在!!非常感谢!
  • @JustinJungheeKim 这里没有说谢谢的规则,如果解决方案有效,则将答案标记为已接受或赞成,以便其他用户可以作为参考。
猜你喜欢
  • 1970-01-01
  • 2013-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-19
  • 2020-01-12
  • 2015-12-15
  • 2014-09-09
相关资源
最近更新 更多