Home > database >  Doesn't work stdout.write Method but can work stdout.writeln
Doesn't work stdout.write Method but can work stdout.writeln

Time:02-14

import 'dart:io'
void main(){
stdout.write("abc");}

that code doesn't worked but

void main(){
stdout.writeln("abc");}

was work!! output is "abc" and

void main(){
stdout.write("abc");
stdout.writeln("def");}

out put is "abcdef" I can't understand this happend...

CodePudding user response:

Both write and writeln are non-blocking, with the difference that writeln is causing the buffer to be flushed. Your first code would work if you await a flush before ending your program:

import 'dart:io'

void main() async {
    stdout.write("abc");
    await stdout.flush();
}
  • Related