在io包中正确使用函数stdout [英] Proper use of function stdout in io package

查看:410
本文介绍了在io包中正确使用函数stdout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

dart中package io的stdout()函数的正确用法是什么?
我写了一个这样的脚本:

What is proper usage of stdout() function from package io in dart? I wrote such a script:

#import('dart:io');
void main() {
  print("Hello World");
  stdout();
}

,我得到以下输出:


firen @ firen-VirtualBox:〜/下载$ ./dart/dart-sdk/bin/dart
./dart/workspace/test/text.dart Hello world未处理的异常:
对象不是闭包
0.功能:':: main'url:'/home/firen/Downloads/dart/workspace/test/text.dart'line:6 col:7

firen@firen-VirtualBox:~/Downloads$ ./dart/dart-sdk/bin/dart ./dart/workspace/test/text.dart Hello world Unhandled exception: Object is not closure 0. Function: '::main' url: '/home/firen/Downloads/dart/workspace/test/text.dart' line:6 col:7


推荐答案

import 'dart:io';
void main() {
     String s = "Hello World";
     stdout.write(s.charCodes());
}

stdout是 OutputStream 而不是方法,这是为什么你得到对象不是一个闭包错误,当你尝试调用stdout();

stdout is a property of type OutputStream rather than method, which is why you get the "Object is not a closure" error when you try to call stdout();

这篇关于在io包中正确使用函数stdout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆