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

标签 c++ gcc codeblocks gnu

我的 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;
  }
}

关于c++ - 代码编译,但没有控制台输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31511491/

相关文章:

c++ - 如何使用相同的可执行文件在后台运行 3 QProcess

c++ - 将字符串写入 ostream

python - Pip、pip3 和相互冲突的 Python 发行版

gcc - 如何在我的 C++ Android 应用程序中启用 VFP 或 NEON 支持?

html - 在 Markdown 中创建嵌套列表而不是代码块

c++ - boost::circular_buffer 如何处理覆盖移位

c++ - 即使头文件中未定义静态变量,也会出现重定义错误?

ide - 在代码块中启用编译器输出 Pane

c++ - 命名空间错误 'Not a namespace-name'

c++ - 静态库缺少 `__imp_` 符号