Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8913025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:21:28+00:00 2026-06-15T04:21:28+00:00

I intend to make a tokenizer. I need to read every line the user

  • 0

I intend to make a tokenizer. I need to read every line the user types and stop reading once the user presses Ctrl + D.

I searched around and only found one example on Rust IO which does not even compile. I looked at the io module’s documentation and found that the read_line() function is part of the ReaderUtil interface, but stdin() returns a Reader instead.

The code that I would like would essentially look like the following in C++:

vector<string> readLines () {
    vector<string> allLines;
    string line;

    while (cin >> line) {
        allLines.push_back(line);
    }

    return allLines;
}

This question refers to parts of Rust that predate Rust 1.0, but the general concept is still valid in Rust 1.0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:21:29+00:00Added an answer on June 15, 2026 at 4:21 am

    In Rust 0.4, use the ReaderUtil trait to access the read_line function. Note that you need to explicitly cast the value to a trait type, for example, reader as io::ReaderUtil:

    fn main() {
        let mut allLines = ~[];
        let reader = io::stdin();
    
        while !reader.eof() {
                allLines.push((reader as io::ReaderUtil).read_line());
        }
    
        for allLines.each |line| {
                io::println(fmt!("%s", *line));
        }
    }
    

    This answer predates Rust 1.0. Please see the other answers for modern solutions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I intend to make a browser game with jQuery, I would need a canvas
I intend to make an application that is related to parking management.User fills in
I intend to make some software to be sold over internet. I've only created
I intend to make a web application that displays 3d environments that can be
I intend to create a realtime counter. So one user can incremenet the counter
I intend notifying the user 60 seconds before the session expires in asp.net. I
I intend to develop a J2ME application, that should be able to read words
I have a small app I've made that I intend to make available on
I am starting a new web project and I intend to make it API
I intend to make a program that does the following: Create an NSArray populated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.