代码编译,但没有控制台输出

Code compiles, but no console output

我的 C++ 代码编译并运行,但没有输出打印到控制台。我认为它与字符串变量有关,但我不确定。我是一个菜鸟,任何帮助将不胜感激。我在 GNU GCC 编译器中使用代码块。

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string botlong, botshort, secondline;
    botlong = "bottles of beer on the wall,";
    botshort = "bottles of beer";
    secondline = "Take one down and pass it around,";
    for(int bottles = 99; bottles<=0; bottles--)
    {
        cout<<bottles <<botlong <<bottles <<botshort;
        for(int lostB = 98; lostB<=0; lostB--)
        {
            cout<<secondline<<lostB<<botlong;
        }
    }
    return 0;
};

必须是>=而不是<=,否则你的循环是进不去的:

for(int bottles = 99; bottles >= 0; --bottles)
{
  cout << bottles << botlong << bottles << botshort;
  for(int lostB = 98; lostB >= 0; --lostB)
  {
    cout << secondline << lostB << botlong;
  }
}

我认为您在 for 循环中的条件在开始时不成立。您有错字,请将 bottles<=0 更正为 bottles>=0 并与下一个 for 循环相同。