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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:32:58+00:00 2026-05-17T20:32:58+00:00

Essentially what I’m looking for is a function with the following prototype: string getln(istream);

  • 0

Essentially what I’m looking for is a function with the following prototype: string getln(istream);
All I need it to do is work like PHP’s fgets(), that is, take an input stream as a parameter and return the next line from the stream.

I feel like my current approach is somewhat bulky for creating a temporary variable each time it’s called:
string getln(istream &input) { string rtn; getline(input, rtn); return rtn; }

Are there any better solutions?


Background:
I’m not looking for a function like this for assignment operations (like some_str = getln(ifile);) but I’m trying to use it as a data source for a stringstream. Ultimately I want a smaller version of getline(ifile, tmp); string_str.str(tmp); that looks a bit more like string_str.str(getln(ifile)); but without the overhead of my example function creating a temp variable each time.

If I’m being too picky about this, feel free to call me out on it. I’m just hoping to see if there’s a way to improve on my method.

  • 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-17T20:32:59+00:00Added an answer on May 17, 2026 at 8:32 pm

    You’re being picky. Any function that returns a string is going to have a string variable that’s declared, filled, and returned, just like the function you’ve already written.

    Besides, the “named return-value optimization” allows the compiler to elide the extra variable sometimes. The caller will allocate space for the object and pass it to your function, where it will be modified as though it were the rtn variable; no copy will be made while returning because the value is already in the desired location.

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

Sidebar

Related Questions

Essentially, I would like to create a new process and define the environment for
Essentially I would like to add a UIImage programmatically to my interface, using: [[self
Essentially, I have a methods that manipulates data taken from a table to create
Essentially I have lots of small urls with parameters. a requirement is for users
Essentially, I currently have an iPhone app that can query and parse an XML
Essentially, what I want to do is this: gcc foo.c -o foo.o ar rcs
Essentially, I'm trying to achieve the affect of text-align:justify but with floating block elements.
Essentially I want the text to fadeIn,delay for a 3 seconds and then fadeOut.
I essentially want to create a variable that would be executed every time. For

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.