c++ - 尝试 If 语句

标签 c++ visual-c++

这个 if 语句不起作用。

谁能告诉我为什么下面的代码不起作用,并帮助我修复?

i=0;

while(1)
{
   if(counter2 < storeanother[0].size())
      break;

 int j=0;

  while(1)
 {
   if(j < handler)
      break;

     outputFile2 << storeanother[0][counter2] << "   +   " << storeanother[1][counter2] << " =   " << z80[i].get(j) << endl;
     counter2+=1;

      j++;
 }
 i++;
}
   outputFile2.close();

最佳答案

你反转条件

for (init; cond, post) { body;}

相当于

init;
while (true) {
    if (!cond) { // and not simply cond
        break;
    }
    body;
    post;
}

甚至

init;
while (cond) {
    body;
    post;
}

所以

if(counter2 < storeanother[0].size())
    break;

应该是

if (counter2 >= storeanother[0].size())
    break;

和另一个循环类似。

关于c++ - 尝试 If 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34331289/

相关文章:

c++ - 在 MSVC 2010 中编译 64 位应用程序

qt - Qt中的QString查找方法?

c++ - 当参数是目录时,Ifstream open() 不设置错误位

c++ - 在 C++ 中,为什么无法初始化指向函数的指针?

C++ 悬挂指针和内存泄漏

android - 找不到 opencv.hpp?安卓NDK

c++ - 如何在运行时检索#pragma 注释数据?

c++ - 如何避免在 Visual Studio 中调试到 Boost 源代码?

c++ - 我在代码中的几行中得到了这个 "warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)"

c++ - 链接器提示找不到现有方法 (C++)