编译代码,但没有控制台输出
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
循环相同。
相关文章:
- C++:将控制台输出存储在宏中更好吗
- 在Qt Creator中,如何在连接到正在运行的进程后查看控制台输出
- 控制台输出在 Qt5 中未正确显示
- 有人可以向我解释为什么控制台输出 0 吗?
- 使用 std::string_view 的子字符串控制台输出
- C++ 如何暂停控制台输出,以便用户可以在继续之前阅读信息
- 我如何阅读简单的控制台输出
- 是否可以在 RTL(从右到左)中制作控制台输出?
- 如何让控制台输出覆盖控制台而不是纯文本输出?
- 乱码控制台输出管道 stderr 到更多
- 将控制台输出写入.txt并在控制台上显示
- 当被一个输入分开时,有两个控制台输出同时显示
- VSCode C++调试捕获控制台输出
- 如何将控制台输出中的所有内容复制到文本文件?
- C++ 使用简单的代码同时写入文件和控制台输出
- 使控制台输出是否"verbose"的最快方法
- 将 ffmpeg 控制台输出重定向到C++中的字符串或文件
- C++ 控制台输出到 cmd 在重复十次后出错
- 从控制台输出读取 C++
- 如何将控制台输出的文本颜色更改为红色,但如果从Powershell或CMD运行,背景将保持相同的颜色