Here i have skipped 7 line but now i want to get result from that result which i have skipped. I want to get 1st line from it but i can not get it then how can i get this first line?

use std::fs::File;

use std::io::{Write, BufReader, BufRead};

use std::io;

fn main() {



fn run() -> Result<(), io::Error> {

let path = "hosts.txt";

let mut output = File::create(path)?;

write! (output, "host, Ip


# Host Database


# localhost is used to configure the loopback interface

# when the system is booting.  Do not change this entry.

## localhost   broadcast host

::1  localhost")?;

let input = File::open(path)?;

let buffered = BufReader::new(input);

for line in buffered.lines().skip(7  ) {   // I need to skip the first line of the file

    let record = line?;

    println!("{:#?}", record);

    let mut dog = String::new();

    record::stdin().read_line(&mut dog).unwrap();

    println!("Hello {}!", dog);

    let data: Vec<&str> = record.split_whitespace().collect();


let buffered_lines = buffered.lines();
let first_line =;

for line in buffered_lines.skip(7) {
    // …

Is that what you want? I'm not entirely sure, I understood your question and the comment in the code.

I have done this but now I want the first line from that obtained part.

et buffered = BufReader::new(input);

for line in buffered.lines().skip(7  ) {   

    let record = line?;


    println!("{:#?}", record);

    println!("{:#?}", first_line);


I have done this

Please read Forum Code Formatting and Syntax Highlighting and edit your prior posts that include code by using the pencil-shaped edit button under those posts.

Many readers of this forum will ignore code snippets, compiler error reports, etc that do not follow the posting guidelines for new contributors that are pinned to the top of this forum. Even those who do respond may feel that the lack of following the forum posting guidelines is disrespectful of their time. Thanks. :clap:


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.