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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:39:00+00:00 2026-05-26T21:39:00+00:00

Basically I have a thread reading from c++ std::istream using istream& getline ( istream&

  • 0

Basically I have a thread reading from c++ std::istream using

istream& getline ( istream& is, string& str );

And when I bind the istream with cin, then it works fine when I type the input from standard command line as the input.

But I am wondering is there a way that I can make the read thread getline get the string without
using the actual command line ?

Basically I want to achieve this:

By just calling a function WriteToIStream with parameter str (instead of type str in command line) and the read thread getilne() can get the str.

void WriteToIStream(string& str)
{
//...
}

Many Thanks

  • 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-26T21:39:00+00:00Added an answer on May 26, 2026 at 9:39 pm

    cin is only one instance of an input stream, bound to the standard input. For your case, you can use an istringstream (or more generally a stringstream) which is an input stream to read from a string:

    std::istringstream istr("foobar");
    getline(istr, some_string_variable);
    

    This requires the standard header <sstream>.

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

Sidebar

Related Questions

basically i am reading image bytes from file i have a loop which has
I'm using multiple threads in my application. Basically I have a combo box and
I basically have the following string in the format: A,B,C:D,E,F What I am trying
I have been reading up on using webrequests and post and get methods to
I have a project using curses and sockets to make a talking program. Basically
I basically have an application that has, say 5 threads, which each read from
I have been trying to solve a problem involving thread communication using wait() and
I have been reading about the thread-pool pattern and I can't seem to find
see basically i have one multi-thread application in which i want to see the
I'm getting an weird error using queues/multiprocessing. I basically have a function that takes

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.