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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:34:06+00:00 2026-05-28T04:34:06+00:00

everyone. I am an experienced C programmer trying to get adjusted to C++. I

  • 0

everyone. I am an experienced C programmer trying to get adjusted to C++. I would like to do the equivalent of this C statement…

sscanf(str, "%s %s", sub1, sub2);

…but with C++’s string object. Say str is “hello world”, doing the above sscanf statement would put “hello” in sub1, and “world” in sub2. I know I can use C functions like that in C++, but I would like to use the C++ string object instead of an array of chars. I’ve tried this:

string q, h, w;
cout << "Type \"hello world\": ";
cin >> q;
istringstream x(q);
x >> h >> w;
if (h == "hello")
    cout << "Yes!\n";
else
    cout << "No!\n";
if (w == "world")
    cout << "Yes!\n";
else
    cout << "No!\n";

But it outputs “Yes! No!”, which means it picked up the “hello” but not the “world”. Any ideas?

  • 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-28T04:34:06+00:00Added an answer on May 28, 2026 at 4:34 am

    That is because the operator>> used with cin will only capture the “hello” phrase, and will stop at the first delimiter (in this case a space). If you want to capture the entire input line up to the first line-delimiter typed by the user, you will have to use getline(cin, q). The two-argument version of getline() uses a newline as the delimiter, but there is a three-argument version that allows you to specify a custom line-delimiter character as well.

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

Sidebar

Related Questions

Even experienced programmers write C# code like this sometimes: double x = 2.5; double
Hey everyone. I am an experienced java programmer and am just learning C++. Now
This question can have different answers because everyone would do it his own way.
So I've been trying to do some research and would like the opinions of
Everyone has this huge massively parallelized supercomputer on their desktop in the form of
Everyone is familiar with this functionality. If you open up the the outlook address
Everyone uses source-code control to manage versions (right?) and this provides some level of
I think everyone has experience working with a code like the following: void fun(Type1&);
I am a systems programmer, so i just know some basic css/html. I like
I suppose this is two very closely related questions: Everyone says to start with

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.