首页 > 解决方案 > cout 在 switch 语句中不起作用

问题描述

再会,

我有一个循环计算值并将输出显示到控制台。但是,当我运行代码时,cout <<不会显示我预期的输出。事实上,它不显示任何输出。我知道代码甚至可以工作的唯一方法是值正在发生变化。

cout <<在我使用 switch 语句之前工作得很好。我希望在语句和循环中打印到控制台的每一段文本都是死文本。它没有用。我还尝试使用cout.flush. 那也不起作用,我不能包含我的所有代码,但这里有问题:

if (exampleloop == '1'){
  ExampleValue = (ExampleValue - 1);
  ExampleValue = (ExampleValue - ExampleValue);
  cout << "ExampleText " << ExampleValue << " ExampleText";

  if (ExampleValue <= 0){
    cout << "ExampleText.";
  }

  if (ExampleValue <= 0){
    cout << ExampleText";
  }

  example_label:
  ExampleValue = (ExampleValue1 - ExampleValue1);
  cout << "ExampleText! " << ExampleValue! << " ExampleText!";
  goto Example_label;
}

我知道正在计算代码的唯一方法

cout << "EXAMPLE TEXT  ExampleValue1 at "<< ExampleValue <<" . ExampleText";

在这种情况下,“示例文本”将永远不会出现在控制台上。但是,将计算“示例值”,并且更改将反映在上面的代码中。

我的 IDE 是 repl.it

这是我的错,还是我的 IDE 的错?发生了什么事?

(是的,我#include iostream和我是using namespace std

标签: c++if-statementcout

解决方案


推荐阅读