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 885183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:52:05+00:00 2026-05-15T12:52:05+00:00

For Example: If I need to read a multiple line input like(and I dont

  • 0

For Example:
If I need to read a multiple line input like(and I dont know How many lines would be there!!):

1 20

2 31

3 41

I am using something like

int main()
{
  string line;

  while(getline(cin,line) != NULL)
  {
       // some code
       // some code    
  }


}

Now the program never stops- i.e always it expects some input. How do i beak the loop when there are no more input lines ?

  • 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-05-15T12:52:06+00:00Added an answer on May 15, 2026 at 12:52 pm

    Just test the variable line for empty each time you read a line. If the use presses enter with no other data, then line will be empty.

    #include <iostream>
    #include <string>
    
    using std::cin;
    using std::getline;
    using std::string;
    
    int main(int argc, char *argv[]) {
    
        string line;
    
        while (true) {
            getline(cin, line);
            if (line.empty()) {
                break;
            }
            // some code
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to read a single file using multiple threads under Linux. There are
I have a std::string with multiple lines and I need to read it line
I just want to read multiple lines in a file. For example in sample.txt
I need to call a stored procedure multiple times, I'm using informix. I would
I need a code example or library which would parse Accept-Language header and return
If I am using ReaderWriterLockSlim to acquire read/write locks, do I need to make
Can anyone please help me with the code as how to read multiple lines
I've read the questions/answers explaining that there is no multiple inheritance in C# ,
I would like to execute multiple commands in a row: i.e. (just to illustrate
For Example: I need to develop a Small Inventory program for nearby Super Market

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.