dartpad不支持I/O吗?
Does dartpad not support I/O?
最近我在 DartPad 上尝试了“Dart For Absolute Beginners”中的一些代码片段。
具体来说:
import 'dart:math';
import 'dart:io';
void main()
{
int guess;
Random rand = new Random(); //create a random number generator
int answer = rand.nextInt(100); //gets a random integer from 0 to 99
do
{
print("Enter your guess:");
String temp = stdin.readLineSync(); //read in from the keyboard
guess = int.parse(temp); //convert String to integer
if (guess < answer)
{
print("Too low!");
}
else if (guess > answer)
{
print("Too high!");
}
}
while (guess != answer);
print("You got it!");
}
但是在 运行ning 时,它显示错误“编译到 JavaScript 时出错:
不支持的导入:dart:io"
所以我的问题是
难道我们不能在 DartPad 上进行 运行 I/O 操作,我们需要一个完整的编辑器吗?
还是有其他问题??
DartPad 不支持 dart:io
库。但是你可以使用 this Dart 编译器,它支持 dart:io
.
如 dart:io
documentation 中所述:
Important: Browser-based apps can't use this library. Only the following can import and use the dart:io library:
- Servers
- Command-line scripts
- Flutter mobile apps
- Flutter desktop apps
最近我在 DartPad 上尝试了“Dart For Absolute Beginners”中的一些代码片段。 具体来说:
import 'dart:math';
import 'dart:io';
void main()
{
int guess;
Random rand = new Random(); //create a random number generator
int answer = rand.nextInt(100); //gets a random integer from 0 to 99
do
{
print("Enter your guess:");
String temp = stdin.readLineSync(); //read in from the keyboard
guess = int.parse(temp); //convert String to integer
if (guess < answer)
{
print("Too low!");
}
else if (guess > answer)
{
print("Too high!");
}
}
while (guess != answer);
print("You got it!");
}
但是在 运行ning 时,它显示错误“编译到 JavaScript 时出错: 不支持的导入:dart:io"
所以我的问题是
难道我们不能在 DartPad 上进行 运行 I/O 操作,我们需要一个完整的编辑器吗? 还是有其他问题??
DartPad 不支持 dart:io
库。但是你可以使用 this Dart 编译器,它支持 dart:io
.
如 dart:io
documentation 中所述:
Important: Browser-based apps can't use this library. Only the following can import and use the dart:io library:
- Servers
- Command-line scripts
- Flutter mobile apps
- Flutter desktop apps