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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:18:59+00:00 2026-06-17T22:18:59+00:00

I ran into an unexpected compilation error when trying to use getline() with a

  • 0

I ran into an unexpected compilation error when trying to use getline() with a temporary stream object:

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main()
{
    string input = "hello\nworld\nof\ndelimiters";

    string line;
    if (getline(stringstream(input), line)) // ERROR!
    {
        cout << line << endl;
    }
}

It looks like no overload of getline() exists that accepts an rvalue reference to a stream object. If I change main() to use an lvalue, it compiles and runs as expected:

int main()
{
    string input = "hello\nworld\nof\ndelimiters";

    string line;
    stringstream ss(inpupt);
    if (getline(ss, line)) // OK
    {
        cout << line << endl;
    }
}

So I had a look in the C++11 Standard and I found out (§ 21.4.8.9) that an overload of getline() that takes an rvalue reference to a stream object should be present.

Am I missing something obvious, or is this a bug? The error occurs both with GCC 4.7.2 and with Clang 3.2. I cannot test this on VC at the moment.

  • 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-17T22:19:01+00:00Added an answer on June 17, 2026 at 10:19 pm

    If I compile on OS X with the following line, it compiles successfully. What version of the libstdc++ or libc++ are you using?

    clang++ -std=c++11 -stdlib=libc++ foo.cc
    

    libstdc++ (and libc++ for that matter) do not yet fully implement the C++ 2011 standard library. This appears to be one of the missing functions from libstdc++.

    Sadly, I don’t know of any resource that lists exactly what is missing from each implementation.

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

Sidebar

Related Questions

Ran into an Out of Stack Space error trying to serialize an ASP.Net AJAX
Ran into this error message while trying to select some records off a table.
While creating a map of String to partial functions I ran into unexpected behavior.
I'm trying to include C code into a simple C++ program but I ran
While trying to deploy with capistrano and git I ran into this error: [178.79.133.74]
I've just ran into an unexpected behaviour for Entity framework entities in use with
I recently endeavoured to learn about multiple threading, and ran into the following unexpected
I ran into unexpected behavior with a function I wrote to compute the average
Background: I ran into a problem that I find somewhat unexpected. I have a
I've been playing around with Backbone.js and ran into something a bit unexpected. It

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.