最新的 VS Code – 一个简单的控制台应用程序,用于询问数字。

huangapple go评论68阅读模式
英文:

latest vs code - simple console app to ask for number

问题

我有一个简单的控制台应用程序,要求用户输入两个数字。然而,当我尝试运行它时,我没有收到提示?这似乎很简单?

我尝试了以下两种方式:

dotnet new console
dotnet new console --use-program-main
// 有关更多信息,请参阅 https://aka.ms/new-console-template
Console.Write("第一个数字? ");
var number1 = Convert.ToInt16(Console.ReadLine());
Console.Write("第二个数字? ");
var number2 = Convert.ToInt16(Console.ReadLine());

在使用命令行并转到 bin 目录并在那里执行时,它表现如预期。

最新的 VS Code – 一个简单的控制台应用程序,用于询问数字。
最新的 VS Code – 一个简单的控制台应用程序,用于询问数字。
最新的 VS Code – 一个简单的控制台应用程序,用于询问数字。

英文:

I have a simple console app that asks the user for 2 numbers. However, when I try to run it I'm not getting the prompts? This seems so simple?

I've tried both

dotnet new console
dotnet new console --use-program-main


// See https://aka.ms/new-console-template for more information
Console.Write("First number? ");
var number1 = Convert.ToInt16(Console.ReadLine());
Console.Write("Second number? ");
var number2 = Convert.ToInt16(Console.ReadLine());

最新的 VS Code – 一个简单的控制台应用程序,用于询问数字。

最新的 VS Code – 一个简单的控制台应用程序,用于询问数字。

When I use cmd line and goto bin and execute it there it behaves as expected.

最新的 VS Code – 一个简单的控制台应用程序,用于询问数字。

答案1

得分: 1

The debug console (which is what you are selected on in your screenshot) doesn't accept any kind of input for a running program.

According to Microsoft Documentation:

The Debug Console doesn't accept terminal input for a running program. To handle terminal input while debugging, you can use the integrated terminal (one of the Visual Studio Code windows) or an external terminal.

As this states, you need to use the integrated terminal is Visual Studio Code, or an external one. The documentation also states how to do this. To summarize:

  1. Open your launch.json file used for debugging.
  2. Change the console property to be either integratedTerminal or externalTerminal.

If you opt to use the integrated terminal, when you debug, switch to the "Terminal" tab, and you'll see your prompts:

最新的 VS Code – 一个简单的控制台应用程序,用于询问数字。

英文:

The debug console (which is what you are selected on in your screenshot) doesn't accept any kind of input for a running program.

According to Microsoft Documentation:

> The Debug Console doesn't accept terminal input for a running program. To handle terminal input while debugging, you can use the integrated terminal (one of the Visual Studio Code windows) or an external terminal.

As this states, you need to use the integrated terminal is Visual Studio Code, or an external one. The documentation also states how to do this. To summarize:

  1. Open your launch.json file used for debugging.
  2. Change the console property to be either integratedTerminal or externalTerminal.

If you opt to use the integrated terminal, when you debug, switch to the "Terminal" tab, and you'll see your prompts:

最新的 VS Code – 一个简单的控制台应用程序,用于询问数字。

huangapple
  • 本文由 发表于 2023年5月21日 05:25:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76297409.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定