Rust program to demonstrate the use of std::io::stdout().write() function

Rust Example: Write a program to demonstrate the use of std::io::stdout().write() function.
Submitted by Nidhi, on November 25, 2021

Problem Solution:

In this program, we will demonstrate the use of std::io::stdout().write() function. This function is used to write data on the standard output device and it returns total bytes written on the standard output device successfully.

Program/Source Code:

The source code to demonstrate the use of std::io::stdout().write() function is given below. The given program is compiled and executed on UBUNTU 18.04 successfully.

// Rust program to demonstrate the use of 
// std::io::stdout().write() function

use std::io::Write;

fn main() {
   let bytes = std::io::stdout().write("Hello World".as_bytes()).unwrap();
   
   println!("\nTotal byte written: {}",bytes);
}

Output:

Hello World
Total byte written: 11

Explanation:

In the main() function, we used std::io::stdout().write() function to write data on the standard output device that is "monitor". It returns the total number of bytes written successfully.

Rust Miscellaneous Programs »





Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.