Jay Tillu
Jay Tillu

Reputation: 1558

If both adds newline after message, What is the difference between print() and stdout.writeln() in dart?

here is my simple dart code.

import 'dart:io';

main(){
    print("Hello World");
    stdout.writeln("Another Hello World");
}

output:

Hello World   //Prints newline by default. 
Another Hello World    //Also print newline after this.

If both functions print a newline after printing, then what is the difference between both of them.

Upvotes: 4

Views: 915

Answers (2)

Mou Biswas
Mou Biswas

Reputation: 324

For print() it brings the cursor to the next line as the work ends there, and another hand stdout.write makes to stay the cursor at the same line, yet it adds the newline.

Upvotes: 0

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76323

On the DartVM the behaviours are the same. But when Dart code runs in browser you cannot use stdout. dart:io library can not be used in Browser-based applications. print been part of the core library it can be used everywhere.

A little difference (also on VM) is that print can be overriden with Zone.

Upvotes: 7

Related Questions