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

  • Home
  • SEARCH
  • 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 7853085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:34:42+00:00 2026-06-02T19:34:42+00:00

I have to read input according to these rules: The input consists of several

  • 0

I have to read input according to these rules:

“The input consists of several lines of text. Some lines may be empty. The input can be fed from a file, using a line such as prog.exe < input.txt in which case the end of input is indicated appropriatelly by the operating system. If you enter input using a keyboard, there is normally a way to signal the end of input with some control key, depending on the operating system (e.g., Ctrl+d in Unix/Linux-style systems, and Ctrl+z in Microsoft systems).”

Previously I have been doing it this way

while(getline(cin, data)) {
     if(data == "0") break;
     / * do stuff */
}

So I can read as many lines as I want and preform calculations, and then when I’m done just type a 0 and end my program. I tried entering a list of things in a .txt file one per line, and then calling program.exe < myfile.txt but nothing happened.

What’s this < file.txt doing?

How can I properly handle content inside it when calling my program like that?

And how can I make it calculate things when you hit ctrl+z?

  • 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-02T19:34:43+00:00Added an answer on June 2, 2026 at 7:34 pm

    Paraphrasing the text of your exercise:

    Using command1 < file1 executes command1, with file1 as the source of input (as opposed to the keyboard).

    This is known as redirecting standard input.

    std::cin will get its input from file1 instead of from the keyboard.

    The end of the input file is analogous to CTRL+Z (on Microsoft systems, CTRL+D on most others). Once std::getline() reaches the end of the file (or you read a line with just “0”), you’ll exit your while-loop and then you can do your calculation on the data you’ve collected (and presumably stored in some container).

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

Sidebar

Related Questions

I have a php script that gets user input (some text and a link),
I have read this. Jquery checkbox <input type=checkbox name=checkGroup id=all> <input type=checkbox name=checkGroup id=one
Im writing a program that should read input via stdin, so I have the
I have read some of the questions and answers here, but it none match
I have a text area and I would like to take the input of
So I want to read a text file but for some strange reason it
I have read on Stack Overflow some people that have converting to C#2.0 to
I have created an application that creates bar graph based on inputs read from
I have read many answers to questions about dynamically resizing NSWindows and nothing has
I have read various posts in stackoverflow and I am trying to figure out

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.